@@ 113-124 (lines=12) @@ | ||
110 | * @param callable $fns... |
|
111 | * @return callable |
|
112 | */ |
|
113 | function pipe() { |
|
114 | $fns = func_get_args(); |
|
115 | if(count($fns) < 1) |
|
116 | return identity(); |
|
117 | return function () use ($fns) { |
|
118 | $result = _apply(array_shift($fns), func_get_args()); |
|
119 | foreach ($fns as $fn) { |
|
120 | $result = $fn($result); |
|
121 | } |
|
122 | return $result; |
|
123 | }; |
|
124 | } |
|
125 | ||
126 | /** |
|
127 | * Performs right-to-left function composition. |
|
@@ 144-155 (lines=12) @@ | ||
141 | * @param callable $fns... |
|
142 | * @return callable |
|
143 | */ |
|
144 | function compose() { |
|
145 | $fns = array_reverse(func_get_args()); |
|
146 | if(count($fns) < 1) |
|
147 | return identity(); |
|
148 | return function () use ($fns) { |
|
149 | $result = _apply(array_shift($fns), func_get_args()); |
|
150 | foreach ($fns as $fn) { |
|
151 | $result = $fn($result); |
|
152 | } |
|
153 | return $result; |
|
154 | }; |
|
155 | } |
|
156 | ||
157 | /** |
|
158 | * A function that takes one argument and |