@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | function reduce() { |
101 | 101 | static $reduce = false; |
102 | - $reduce = $reduce ?: curry(function($fn, $initial, $list){ |
|
102 | + $reduce = $reduce ?: curry(function($fn, $initial, $list) { |
|
103 | 103 | return array_reduce($list, $fn, $initial); |
104 | 104 | }); |
105 | 105 | return _apply($reduce, func_get_args()); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | function each() { |
128 | 128 | static $each = false; |
129 | - $each = $each ?: curry(function($fn, $list){ |
|
129 | + $each = $each ?: curry(function($fn, $list) { |
|
130 | 130 | foreach ($list as $item) { |
131 | 131 | $fn($item); |
132 | 132 | } |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | * @param array|string $list |
177 | 177 | * @return mixed |
178 | 178 | */ |
179 | -function last () { |
|
179 | +function last() { |
|
180 | 180 | static $last = false; |
181 | 181 | $last = $last ?: curry(function($list) { |
182 | - if(is_string($list)) |
|
182 | + if (is_string($list)) |
|
183 | 183 | return substr($list, -1); |
184 | 184 | $size = count($list); |
185 | 185 | return ($size > 0) |
@@ -206,10 +206,10 @@ discard block |
||
206 | 206 | * @param array|string $list |
207 | 207 | * @return array |
208 | 208 | */ |
209 | -function init () { |
|
209 | +function init() { |
|
210 | 210 | static $init = false; |
211 | 211 | $init = $init ?: curry(function($list) { |
212 | - if(is_string($list)) { |
|
212 | + if (is_string($list)) { |
|
213 | 213 | $size = strlen($list); |
214 | 214 | return ($size > 1) |
215 | 215 | ? substr($list, 0, $size - 1) |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | * @param array|string $list |
241 | 241 | * @return array |
242 | 242 | */ |
243 | -function tail () { |
|
243 | +function tail() { |
|
244 | 244 | static $tail = false; |
245 | 245 | $tail = $tail ?: curry(function($list) { |
246 | - if(is_string($list)) |
|
246 | + if (is_string($list)) |
|
247 | 247 | return (strlen($list) > 1) |
248 | 248 | ? substr($list, 1) |
249 | 249 | : ''; |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @param array|string $list |
269 | 269 | * @return array |
270 | 270 | */ |
271 | -function reverse () { |
|
271 | +function reverse() { |
|
272 | 272 | static $reverse = false; |
273 | 273 | $reverse = $reverse ?: curry(function($list) { |
274 | 274 | return is_string($list) |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | static $allSatisfies = false; |
322 | 322 | $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) { |
323 | 323 | foreach ($list as $item) { |
324 | - if (! $predicate($item)) |
|
324 | + if (!$predicate($item)) |
|
325 | 325 | return false; |
326 | 326 | } |
327 | 327 | return true; |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | */ |
498 | 498 | function append() { |
499 | 499 | static $append = false; |
500 | - $append = $append ?: curry(function ($item, $list) { |
|
500 | + $append = $append ?: curry(function($item, $list) { |
|
501 | 501 | return is_string($list) |
502 | 502 | ? $list . $item |
503 | 503 | : array_merge($list, [$item]); |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | */ |
524 | 524 | function prepend() { |
525 | 525 | static $prepend = false; |
526 | - $prepend = $prepend ?: curry(function ($item, $list) { |
|
526 | + $prepend = $prepend ?: curry(function($item, $list) { |
|
527 | 527 | return is_string($list) |
528 | 528 | ? $item . $list |
529 | 529 | : array_merge([$item], $list); |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | $length = length($list); |
559 | 559 | if ($count > $length || $count < -$length) |
560 | 560 | return $list; |
561 | - if(is_string($list)) { |
|
561 | + if (is_string($list)) { |
|
562 | 562 | return ($count >= 0) |
563 | 563 | ? substr($list, 0, $count) |
564 | 564 | : substr($list, $count); |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | $count = ($count > 0) |
710 | 710 | ? $count - $length |
711 | 711 | : $count + $length; |
712 | - if(is_string($list)) { |
|
712 | + if (is_string($list)) { |
|
713 | 713 | return ($count >= 0) |
714 | 714 | ? substr($list, 0, $count) |
715 | 715 | : substr($list, $count); |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | $indexOf = $indexOf ?: curry(function($item, $list) { |
1067 | 1067 | if (is_string($list)) { |
1068 | 1068 | $index = strpos($list, $item); |
1069 | - return $index === false ? -1 : $index; |
|
1069 | + return $index === false ? - 1 : $index; |
|
1070 | 1070 | } |
1071 | 1071 | $list = (array) $list; |
1072 | 1072 | $index = 0; |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | return $keys[$index]; |
1078 | 1078 | $index ++; |
1079 | 1079 | } |
1080 | - return -1; |
|
1080 | + return - 1; |
|
1081 | 1081 | }); |
1082 | 1082 | return _apply($indexOf, func_get_args()); |
1083 | 1083 | } |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | $lastIndexOf = $lastIndexOf ?: curry(function($item, $list) { |
1107 | 1107 | if (is_string($list)) { |
1108 | 1108 | $index = strrpos($list, $item); |
1109 | - return $index === false ? -1 : $index; |
|
1109 | + return $index === false ? - 1 : $index; |
|
1110 | 1110 | } |
1111 | 1111 | $list = (array) $list; |
1112 | 1112 | $keys = array_keys($list); |
@@ -1116,7 +1116,7 @@ discard block |
||
1116 | 1116 | return $keys[$index]; |
1117 | 1117 | $index --; |
1118 | 1118 | } |
1119 | - return -1; |
|
1119 | + return - 1; |
|
1120 | 1120 | }); |
1121 | 1121 | return _apply($lastIndexOf, func_get_args()); |
1122 | 1122 | } |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | } |
1152 | 1152 | $index ++; |
1153 | 1153 | } |
1154 | - if (! $found) { |
|
1154 | + if (!$found) { |
|
1155 | 1155 | $result[$size] = $item; |
1156 | 1156 | $size ++; |
1157 | 1157 | } |
@@ -1211,9 +1211,9 @@ discard block |
||
1211 | 1211 | static $groupBy = false; |
1212 | 1212 | $groupBy = $groupBy ?: curry(function($fn, $list) { |
1213 | 1213 | $result = []; |
1214 | - foreach($list as $item) { |
|
1214 | + foreach ($list as $item) { |
|
1215 | 1215 | $index = $fn($item); |
1216 | - if (! isset($result[$index])) |
|
1216 | + if (!isset($result[$index])) |
|
1217 | 1217 | $result[$index] = []; |
1218 | 1218 | $result[$index][] = $item; |
1219 | 1219 | } |
@@ -46,7 +46,7 @@ |
||
46 | 46 | */ |
47 | 47 | function join() { |
48 | 48 | static $join = false; |
49 | - $join = $join ?: curry(function($glue, $pieces){ |
|
49 | + $join = $join ?: curry(function($glue, $pieces) { |
|
50 | 50 | return implode($glue, $pieces); |
51 | 51 | }); |
52 | 52 | return _apply($join, func_get_args()); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function plus() { |
22 | 22 | static $plus = false; |
23 | - $plus = $plus ?: curry(function($x, $y){ |
|
23 | + $plus = $plus ?: curry(function($x, $y) { |
|
24 | 24 | return $x + $y; |
25 | 25 | }); |
26 | 26 | return _apply($plus, func_get_args()); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | function minus() { |
43 | 43 | static $minus = false; |
44 | - $minus = $minus ?: curry(function($x, $y){ |
|
44 | + $minus = $minus ?: curry(function($x, $y) { |
|
45 | 45 | return $x - $y; |
46 | 46 | }); |
47 | 47 | return _apply($minus, func_get_args()); |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function negate() { |
64 | 64 | static $negate = false; |
65 | - $negate = $negate ?: curry(function($x){ |
|
66 | - return -$x; |
|
65 | + $negate = $negate ?: curry(function($x) { |
|
66 | + return - $x; |
|
67 | 67 | }); |
68 | 68 | return _apply($negate, func_get_args()); |
69 | 69 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | function multiply() { |
86 | 86 | static $multiply = false; |
87 | - $multiply = $multiply ?: curry(function($x, $y){ |
|
87 | + $multiply = $multiply ?: curry(function($x, $y) { |
|
88 | 88 | return $y * $x; |
89 | 89 | }); |
90 | 90 | return _apply($multiply, func_get_args()); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | function divide() { |
107 | 107 | static $divide = false; |
108 | - $divide = $divide ?: curry(function($x, $y){ |
|
108 | + $divide = $divide ?: curry(function($x, $y) { |
|
109 | 109 | return $x / $y; |
110 | 110 | }); |
111 | 111 | return _apply($divide, func_get_args()); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | function modulo() { |
128 | 128 | static $modulo = false; |
129 | - $modulo = $modulo ?: curry(function($x, $y){ |
|
129 | + $modulo = $modulo ?: curry(function($x, $y) { |
|
130 | 130 | return $x % $y; |
131 | 131 | }); |
132 | 132 | return _apply($modulo, func_get_args()); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | function min() { |
188 | 188 | static $min = false; |
189 | - $min = $min ?: curry(function($a, $b){ |
|
189 | + $min = $min ?: curry(function($a, $b) { |
|
190 | 190 | return $a < $b ? $a : $b; |
191 | 191 | }); |
192 | 192 | return _apply($min, func_get_args()); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | function minBy() { |
211 | 211 | static $minBy = false; |
212 | - $minBy = $minBy ?: curry(function($fn, $a, $b){ |
|
212 | + $minBy = $minBy ?: curry(function($fn, $a, $b) { |
|
213 | 213 | return $fn($a) < $fn($b) ? $a : $b; |
214 | 214 | }); |
215 | 215 | return _apply($minBy, func_get_args()); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | function max() { |
233 | 233 | static $max = false; |
234 | - $max = $max ?: curry(function($a, $b){ |
|
234 | + $max = $max ?: curry(function($a, $b) { |
|
235 | 235 | return $a > $b ? $a : $b; |
236 | 236 | }); |
237 | 237 | return _apply($max, func_get_args()); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | function maxBy() { |
256 | 256 | static $maxBy = false; |
257 | - $maxBy = $maxBy ?: curry(function($fn, $a, $b){ |
|
257 | + $maxBy = $maxBy ?: curry(function($fn, $a, $b) { |
|
258 | 258 | return $fn($a) > $fn($b) ? $a : $b; |
259 | 259 | }); |
260 | 260 | return _apply($maxBy, func_get_args()); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | function has() { |
175 | 175 | static $has = false; |
176 | - $has = $has ?: curry(function($name, $object){ |
|
176 | + $has = $has ?: curry(function($name, $object) { |
|
177 | 177 | if (is_object($object)) return isset($object->{$name}); |
178 | 178 | if (is_array($object)) return isset($object[$name]); |
179 | 179 | return false; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | function get() { |
210 | 210 | static $get = false; |
211 | - $get = $get ?: curry(function($name, $object){ |
|
211 | + $get = $get ?: curry(function($name, $object) { |
|
212 | 212 | return is_object($object) |
213 | 213 | ? (isset($object->{$name}) ? $object->{$name} : null) |
214 | 214 | : (isset($object[$name]) ? $object[$name] : null); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | function curry($fn) { |
35 | 35 | $n = _number_of_args($fn); |
36 | - switch($n) { |
|
36 | + switch ($n) { |
|
37 | 37 | case 0: return $fn; |
38 | 38 | case 1: return _curry_one($fn); |
39 | 39 | case 2: return _curry_two($fn); |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | */ |
103 | 103 | function pipe() { |
104 | 104 | $fns = func_get_args(); |
105 | - if(count($fns) < 1) |
|
105 | + if (count($fns) < 1) |
|
106 | 106 | return identity(); |
107 | - return function () use ($fns) { |
|
107 | + return function() use ($fns) { |
|
108 | 108 | $result = _apply(array_shift($fns), func_get_args()); |
109 | 109 | foreach ($fns as $fn) { |
110 | 110 | $result = $fn($result); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $predicates = func_get_args(); |
182 | 182 | return _curry_one(function($value) use(&$predicates) { |
183 | 183 | foreach ($predicates as $predicate) { |
184 | - if (! $predicate($value)) |
|
184 | + if (!$predicate($value)) |
|
185 | 185 | return false; |
186 | 186 | } |
187 | 187 | return true; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | static $comparator = false; |
280 | 280 | $comparator = $comparator ?: curry(function($fn) { |
281 | 281 | return function($a, $b) use($fn) { |
282 | - if ($fn($a, $b)) return -1; |
|
282 | + if ($fn($a, $b)) return - 1; |
|
283 | 283 | if ($fn($b, $a)) return 1; |
284 | 284 | return 0; |
285 | 285 | }; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | function and_() { |
24 | 24 | static $and = false; |
25 | - $and = $and ?: curry(function($a, $b){ |
|
25 | + $and = $and ?: curry(function($a, $b) { |
|
26 | 26 | return $a && $b; |
27 | 27 | }); |
28 | 28 | return _apply($and, func_get_args()); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | function or_() { |
47 | 47 | static $or = false; |
48 | - $or = $or ?: curry(function($a, $b){ |
|
48 | + $or = $or ?: curry(function($a, $b) { |
|
49 | 49 | return $a || $b; |
50 | 50 | }); |
51 | 51 | return _apply($or, func_get_args()); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return bool |
86 | 86 | */ |
87 | 87 | function eq() { |
88 | - $eq = curry(function($a, $b){ |
|
88 | + $eq = curry(function($a, $b) { |
|
89 | 89 | return $a == $b; |
90 | 90 | }); |
91 | 91 | return _apply($eq, func_get_args()); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | function notEq() { |
108 | 108 | static $notEq = false; |
109 | - $notEq = $notEq ?: curry(function($a, $b){ |
|
109 | + $notEq = $notEq ?: curry(function($a, $b) { |
|
110 | 110 | return $a != $b; |
111 | 111 | }); |
112 | 112 | return _apply($notEq, func_get_args()); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | function eqq() { |
128 | 128 | static $eqq = false; |
129 | - $eqq = $eqq ?: curry(function($a, $b){ |
|
129 | + $eqq = $eqq ?: curry(function($a, $b) { |
|
130 | 130 | return $a === $b; |
131 | 131 | }); |
132 | 132 | return _apply($eqq, func_get_args()); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | */ |
148 | 148 | function notEqq() { |
149 | 149 | static $notEqq = false; |
150 | - $notEqq = $notEqq ?: curry(function($a, $b){ |
|
150 | + $notEqq = $notEqq ?: curry(function($a, $b) { |
|
151 | 151 | return $a !== $b; |
152 | 152 | }); |
153 | 153 | return _apply($notEqq, func_get_args()); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | function lt() { |
266 | 266 | static $lt = false; |
267 | - $lt = $lt ?: curry(function($a, $b){ |
|
267 | + $lt = $lt ?: curry(function($a, $b) { |
|
268 | 268 | return $a < $b; |
269 | 269 | }); |
270 | 270 | return _apply($lt, func_get_args()); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | function lte() { |
288 | 288 | static $lte = false; |
289 | - $lte = $lte ?: curry(function($a, $b){ |
|
289 | + $lte = $lte ?: curry(function($a, $b) { |
|
290 | 290 | return $a <= $b; |
291 | 291 | }); |
292 | 292 | return _apply($lte, func_get_args()); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | */ |
309 | 309 | function gt() { |
310 | 310 | static $gt = false; |
311 | - $gt = $gt ?: curry(function($a, $b){ |
|
311 | + $gt = $gt ?: curry(function($a, $b) { |
|
312 | 312 | return $a > $b; |
313 | 313 | }); |
314 | 314 | return _apply($gt, func_get_args()); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | function gte() { |
332 | 332 | static $gte = false; |
333 | - $gte = $gte ?: curry(function($a, $b){ |
|
333 | + $gte = $gte ?: curry(function($a, $b) { |
|
334 | 334 | return $a >= $b; |
335 | 335 | }); |
336 | 336 | return _apply($gte, func_get_args()); |
@@ -35,8 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function _number_of_args($fn) { |
37 | 37 | $reflector = is_array($fn) ? |
38 | - new \ReflectionMethod($fn[0], $fn[1]) : |
|
39 | - new \ReflectionFunction($fn); |
|
38 | + new \ReflectionMethod($fn[0], $fn[1]) : new \ReflectionFunction($fn); |
|
40 | 39 | return $reflector->getNumberOfRequiredParameters(); |
41 | 40 | } |
42 | 41 | |
@@ -85,7 +84,7 @@ discard block |
||
85 | 84 | function _curry_one($fn) { |
86 | 85 | return function() use($fn) { |
87 | 86 | $args = func_get_args(); |
88 | - return (count($args) > 0 && ! _is_placeholder($args[0])) |
|
87 | + return (count($args) > 0 && !_is_placeholder($args[0])) |
|
89 | 88 | ? $fn($args[0]) |
90 | 89 | : _curry_one($fn); |
91 | 90 | }; |
@@ -79,8 +79,8 @@ |
||
79 | 79 | */ |
80 | 80 | function averageTime($n, $path, $test) { |
81 | 81 | $s = 0; |
82 | - for ($i=0; $i < $n; $i++) { |
|
83 | - $s =+ execute($path, $test->input); |
|
82 | + for ($i = 0; $i < $n; $i ++) { |
|
83 | + $s = + execute($path, $test->input); |
|
84 | 84 | } |
85 | 85 | return $s / $n; |
86 | 86 | } |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -require __DIR__.'/../../vendor/autoload.php'; |
|
2 | +require __DIR__ . '/../../vendor/autoload.php'; |
|
3 | 3 | |
4 | 4 | use Tarsana\Functional as F; |
5 | 5 | use Tarsana\Functional\Stream; |