1
1
2
+ /// Composes an array of functions that take and return the same type.
3
+ ///
4
+ /// - Parameters:
5
+ /// - fs: Zero or more functions to apply in order.
6
+ /// - Returns: A new function that applies every function given as input in order.
7
+ /// - Note: This function is commonly seen in operator form as `<>`.
8
+ public func concat< A> (
9
+ _ fs: [ ( A ) -> A ]
10
+ )
11
+ -> ( A ) -> A {
12
+
13
+ return { ( a: A ) -> A in
14
+ fs. reduce ( a) { a, f in f ( a) }
15
+ }
16
+ }
17
+
2
18
/// Forward composition of functions that take and return the same type.
3
19
///
4
20
/// - Parameters:
@@ -13,8 +29,22 @@ public func concat<A>(
13
29
)
14
30
-> ( A ) -> A {
15
31
16
- return { ( a: A ) -> A in
17
- fz ( fs. reduce ( a) { a, f in f ( a) } )
32
+ return concat ( fs + [ fz] )
33
+ }
34
+
35
+ /// Composes an array of throwing functions that take and return the same type.
36
+ ///
37
+ /// - Parameters:
38
+ /// - fs: Zero or more functions to apply in order.
39
+ /// - Returns: A new function that applies every function given as input in order.
40
+ /// - Note: This function is commonly seen in operator form as `<>`.
41
+ public func concat< A> (
42
+ _ fs: [ ( A ) throws -> A ]
43
+ )
44
+ -> ( A ) throws -> A {
45
+
46
+ return { ( a: A ) throws -> A in
47
+ try fs. reduce ( a) { a, f in try f ( a) }
18
48
}
19
49
}
20
50
@@ -32,32 +62,26 @@ public func concat<A>(
32
62
)
33
63
-> ( A ) throws -> A {
34
64
35
- return { ( a: A ) throws -> A in
36
- try fz ( fs. reduce ( a) { a, f in try f ( a) } )
37
- }
65
+ return concat ( fs + [ fz] )
38
66
}
39
67
68
+ /// Composes an array of mutable functions that mutate the same type.
40
69
///
41
70
/// - Parameters:
42
71
/// - fs: Zero or more functions to apply in order.
43
- /// - fz: A final, optional, terminating function for trailing closure syntax.
44
- /// - a: The argument to the final function.
45
72
/// - Returns: A new function that applies every function given as input in order.
46
73
/// - Note: This function is commonly seen in operator form as `<>`.
47
74
public func concat< A> (
48
- _ fs: ( ( inout A ) -> Void ) ... ,
49
- and fz: @escaping ( _ a: inout A ) -> Void = { _ in }
75
+ _ fs: [ ( inout A ) -> Void ]
50
76
)
51
77
-> ( inout A ) -> Void {
52
78
53
79
return { ( a: inout A ) -> Void in
54
80
fs. forEach { f in f ( & a) }
55
- fz ( & a)
56
81
}
57
82
}
58
83
59
-
60
- /// Forward, mutable value composition of throwing functions that take and return the same type.
84
+ /// Forward composition of mutable functions that mutate the same type.
61
85
///
62
86
/// - Parameters:
63
87
/// - fs: Zero or more functions to apply in order.
@@ -66,53 +90,105 @@ public func concat<A>(
66
90
/// - Returns: A new function that applies every function given as input in order.
67
91
/// - Note: This function is commonly seen in operator form as `<>`.
68
92
public func concat< A> (
69
- _ fs: ( ( inout A ) throws -> Void ) ... ,
70
- and fz: @escaping ( _ a: inout A ) throws -> Void = { _ in }
93
+ _ fs: ( ( inout A ) -> Void ) ... ,
94
+ and fz: @escaping ( _ a: inout A ) -> Void = { _ in }
95
+ )
96
+ -> ( inout A ) -> Void {
97
+
98
+ return concat ( fs + [ fz] )
99
+ }
100
+
101
+ /// Composes an array of mutable, throwing functions that mutate the same type.
102
+ ///
103
+ /// - Parameters:
104
+ /// - fs: Zero or more functions to apply in order.
105
+ /// - Returns: A new function that applies every function given as input in order.
106
+ /// - Note: This function is commonly seen in operator form as `<>`.
107
+ public func concat< A> (
108
+ _ fs: [ ( inout A ) throws -> Void ]
71
109
)
72
110
-> ( inout A ) throws -> Void {
73
111
74
112
return { ( a: inout A ) throws -> Void in
75
113
try fs. forEach { f in try f ( & a) }
76
- try fz ( & a)
77
114
}
78
115
}
79
116
80
- /// Forward, mutable reference composition of functions that take and return the same type.
117
+ /// Forward composition of mutable, throwing functions that mutate the same type.
81
118
///
82
119
/// - Parameters:
83
120
/// - fs: Zero or more functions to apply in order.
84
121
/// - fz: A final, optional, terminating function for trailing closure syntax.
85
122
/// - a: The argument to the final function.
86
123
/// - Returns: A new function that applies every function given as input in order.
87
124
/// - Note: This function is commonly seen in operator form as `<>`.
125
+ public func concat< A> (
126
+ _ fs: ( ( inout A ) throws -> Void ) ... ,
127
+ and fz: @escaping ( _ a: inout A ) throws -> Void = { _ in }
128
+ )
129
+ -> ( inout A ) throws -> Void {
130
+
131
+ return concat ( fs + [ fz] )
132
+ }
133
+
134
+ /// Composes an array of reference-mutable functions that mutate the same type.
135
+ ///
136
+ /// - Parameters:
137
+ /// - fs: Zero or more functions to apply in order.
138
+ /// - Returns: A new function that applies every function given as input in order.
139
+ /// - Note: This function is commonly seen in operator form as `<>`.
88
140
public func concat< A: AnyObject > (
89
- _ fs: ( ( A ) -> Void ) ... ,
90
- and fz: @escaping ( _ a: A ) -> Void = { _ in }
141
+ _ fs: [ ( A ) -> Void ]
91
142
)
92
143
-> ( A ) -> Void {
93
144
94
145
return { ( a: A ) -> Void in
95
146
fs. forEach { f in f ( a) }
96
- fz ( a)
97
147
}
98
148
}
99
149
100
- /// Forward, mutable reference composition of throwing functions that take and return the same type.
150
+ /// Forward composition of reference-mutable functions that mutate the same type.
101
151
///
102
152
/// - Parameters:
103
153
/// - fs: Zero or more functions to apply in order.
104
- /// - fz: A final, optional, terminating function for trailing closure syntax.
105
- /// - a: The argument to the final function.
106
154
/// - Returns: A new function that applies every function given as input in order.
107
155
/// - Note: This function is commonly seen in operator form as `<>`.
108
156
public func concat< A: AnyObject > (
109
- _ fs: ( ( A ) throws -> Void ) ... ,
110
- and fz: @escaping ( _ a: A ) throws -> Void = { _ in }
157
+ _ fs: ( ( A ) -> Void ) ... ,
158
+ and fz: @escaping ( _ a: A ) -> Void = { _ in }
159
+ )
160
+ -> ( A ) -> Void {
161
+
162
+ return concat ( fs + [ fz] )
163
+ }
164
+
165
+ /// Composes an array of reference-mutable, throwing functions that mutate the same type.
166
+ ///
167
+ /// - Parameters:
168
+ /// - fs: Zero or more functions to apply in order.
169
+ /// - Returns: A new function that applies every function given as input in order.
170
+ /// - Note: This function is commonly seen in operator form as `<>`.
171
+ public func concat< A: AnyObject > (
172
+ _ fs: [ ( A ) throws -> Void ]
111
173
)
112
174
-> ( A ) throws -> Void {
113
175
114
176
return { ( a: A ) throws -> Void in
115
177
try fs. forEach { f in try f ( a) }
116
- try fz ( a)
117
178
}
118
179
}
180
+
181
+ /// Forward composition of reference-mutable, throwing functions that mutate the same type.
182
+ ///
183
+ /// - Parameters:
184
+ /// - fs: Zero or more functions to apply in order.
185
+ /// - Returns: A new function that applies every function given as input in order.
186
+ /// - Note: This function is commonly seen in operator form as `<>`.
187
+ public func concat< A: AnyObject > (
188
+ _ fs: ( ( A ) throws -> Void ) ... ,
189
+ and fz: @escaping ( _ a: A ) throws -> Void = { _ in }
190
+ )
191
+ -> ( A ) throws -> Void {
192
+
193
+ return concat ( fs + [ fz] )
194
+ }
0 commit comments