@@ -3,127 +3,127 @@ |
||
3 | 3 | use Tarsana\Functional as F; |
4 | 4 | |
5 | 5 | return F\map(F\apply(F\_f('_stream_operation')), [ |
6 | - ['then', 'Function -> Any -> Any', F\_f('_stream_then')], |
|
7 | - ['and', 'Boolean -> Boolean -> Boolean', F\and_()], |
|
8 | - ['or', 'Boolean -> Boolean -> Boolean', F\or_()], |
|
9 | - ['not', 'Boolean -> Boolean', F\not()], |
|
10 | - ['eq', 'Any -> Any -> Boolean', F\eq()], |
|
11 | - ['notEq', 'Any -> Any -> Boolean', F\notEq()], |
|
12 | - ['eqq', 'Any -> Any -> Boolean', F\eqq()], |
|
13 | - ['notEqq', 'Any -> Any -> Boolean', F\notEqq()], |
|
14 | - ['equals', 'Any -> Any -> Boolean', F\equals()], |
|
15 | - ['equalBy', 'Function -> Any -> Any -> Boolean', F\equalBy()], |
|
16 | - ['lt', 'Any -> Any -> Boolean', F\lt()], |
|
17 | - ['lte', 'Any -> Any -> Boolean', F\lte()], |
|
18 | - ['gt', 'Any -> Any -> Boolean', F\gt()], |
|
19 | - ['gte', 'Any -> Any -> Boolean', F\gte()], |
|
20 | - ['is', 'String -> Any -> Boolean', F\is()], |
|
21 | - ['toString', 'Any -> String', F\toString()], |
|
22 | - ['attributes', 'Object|Array -> Object|Array', F\attributes()], |
|
23 | - ['keys', 'List -> List', F\keys()], |
|
24 | - ['keys', 'Object|Array -> List', F\keys()], |
|
25 | - ['values', 'List -> List', F\values()], |
|
26 | - ['values', 'Object|Array -> List', F\values()], |
|
27 | - ['has', 'Any -> Object|Array -> Boolean', F\has()], |
|
28 | - ['get', 'Any -> Object|Array -> Any', F\get()], |
|
29 | - ['getPath', 'List -> Object|Array -> Any', F\getPath()], |
|
30 | - ['set', 'Any -> Any -> Object|Array -> Object|Array', F\set()], |
|
31 | - ['update', 'Any -> Function -> Object|Array -> Object|Array', F\update()], |
|
32 | - ['satisfies', 'Function -> Any -> Object|Array -> Boolean', F\satisfies()], |
|
33 | - ['satisfiesAll', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAll()], |
|
34 | - ['satisfiesAny', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAny()], |
|
35 | - ['toPairs', 'Object|Array -> List', F\toPairs()], |
|
36 | - ['toPairs', 'List -> List', F\toPairs()], |
|
37 | - ['split', 'String -> String -> List', F\split()], |
|
38 | - ['join', 'String -> List -> String', F\join()], |
|
39 | - ['replace', 'String|List -> String|List -> String -> String', F\replace()], |
|
40 | - ['regReplace', 'String -> String -> String -> String', F\regReplace()], |
|
41 | - ['upperCase', 'String -> String', F\upperCase()], |
|
42 | - ['lowerCase', 'String -> String', F\lowerCase()], |
|
43 | - ['camelCase', 'String -> String', F\camelCase()], |
|
44 | - ['snakeCase', 'String -> String -> String', F\snakeCase()], |
|
45 | - ['startsWith', 'String -> String -> Boolean', F\startsWith()], |
|
46 | - ['endsWith', 'String -> String -> Boolean', F\endsWith()], |
|
47 | - ['test', 'String -> String -> Boolean', F\test()], |
|
48 | - ['match', 'String -> String -> List', F\match()], |
|
49 | - ['occurences', 'String -> String -> Number', F\occurences()], |
|
50 | - ['chunks', 'String -> String -> String -> List', F\chunks()], |
|
51 | - ['map', 'Function -> List -> List', F\map()], |
|
52 | - ['map', 'Function -> Object|Array -> Object|Array', F\map()], |
|
53 | - ['chain', 'Function -> List -> List', F\chain()], |
|
54 | - ['filter', 'Function -> List -> List', F\filter()], |
|
55 | - ['reduce', 'Function -> Any -> List -> Any', F\reduce()], |
|
56 | - ['each', 'Function -> List -> List', F\each()], |
|
57 | - ['head', 'List -> Any', F\head()], |
|
58 | - ['head', 'String -> String', F\head()], |
|
59 | - ['last', 'List -> Any', F\last()], |
|
60 | - ['last', 'String -> String', F\last()], |
|
61 | - ['init', 'List -> Any', F\init()], |
|
62 | - ['init', 'String -> String', F\init()], |
|
63 | - ['tail', 'List -> Any', F\tail()], |
|
64 | - ['tail', 'String -> String', F\tail()], |
|
65 | - ['reverse', 'List -> List', F\reverse()], |
|
66 | - ['reverse', 'String -> String', F\reverse()], |
|
67 | - ['length', 'List -> Number', F\length()], |
|
68 | - ['length', 'String -> Number', F\length()], |
|
69 | - ['allSatisfies', 'Function -> List -> Boolean', F\allSatisfies()], |
|
70 | - ['anySatisfies', 'Function -> List -> Boolean', F\anySatisfies()], |
|
71 | - ['concat', 'List -> List -> List', F\concat()], |
|
72 | - ['concat', 'String -> String -> String', F\concat()], |
|
73 | - ['concatAll', 'List -> List', F\concatAll()], |
|
74 | - ['insert', 'Number -> Any -> List -> List', F\insert()], |
|
75 | - ['insert', 'Number -> String -> String -> String', F\insert()], |
|
76 | - ['insertAll', 'Number -> List -> List -> List', F\insertAll()], |
|
77 | - ['insertAll', 'Number -> String -> String -> String', F\insertAll()], |
|
78 | - ['append', 'Any -> List -> List', F\append()], |
|
79 | - ['append', 'String -> String -> String', F\append()], |
|
80 | - ['prepend', 'Any -> List -> List', F\prepend()], |
|
81 | - ['prepend', 'String -> String -> String', F\prepend()], |
|
82 | - ['take', 'Number -> List -> List', F\take()], |
|
83 | - ['take', 'Number -> String -> String', F\take()], |
|
84 | - ['takeWhile', 'Function -> List -> List', F\takeWhile()], |
|
85 | - ['takeLastWhile', 'Function -> List -> List', F\takeLastWhile()], |
|
86 | - ['takeUntil', 'Function -> List -> List', F\takeUntil()], |
|
87 | - ['takeLastUntil', 'Function -> List -> List', F\takeLastUntil()], |
|
88 | - ['remove', 'Number -> List -> List', F\remove()], |
|
89 | - ['remove', 'Number -> String -> String', F\remove()], |
|
90 | - ['removeWhile', 'Function -> List -> List', F\removeWhile()], |
|
91 | - ['removeLastWhile', 'Function -> List -> List', F\removeLastWhile()], |
|
92 | - ['removeUntil', 'Function -> List -> List', F\removeUntil()], |
|
93 | - ['removeLastUntil', 'Function -> List -> List', F\removeLastUntil()], |
|
94 | - ['fromPairs', 'List -> Object|Array', F\fromPairs()], |
|
95 | - ['slices', 'Number -> List -> List', F\slices()], |
|
96 | - ['slices', 'Number -> String -> List', F\slices()], |
|
97 | - ['contains', 'Any -> List -> Boolean', F\contains()], |
|
98 | - ['contains', 'String -> String -> Boolean', F\contains()], |
|
99 | - ['findIndex', 'Function -> List -> Number|Null', F\findIndex()], |
|
100 | - ['findIndex', 'Function -> Object|Array -> Any', F\findIndex()], |
|
101 | - ['findLastIndex', 'Function -> List -> Number|Null', F\findLastIndex()], |
|
102 | - ['findLastIndex', 'Function -> Object|Array -> Any', F\findLastIndex()], |
|
103 | - ['find', 'Function -> List -> Any', F\find()], |
|
104 | - ['findLast', 'Function -> List -> Any', F\findLast()], |
|
105 | - ['indexOf', 'Any -> List -> Number', F\indexOf()], |
|
106 | - ['indexOf', 'Any -> Object|Array -> Any', F\indexOf()], |
|
107 | - ['indexOf', 'String -> String -> Number', F\indexOf()], |
|
108 | - ['lastIndexOf', 'Any -> List -> Number', F\lastIndexOf()], |
|
109 | - ['lastIndexOf', 'Any -> Object|Array -> Any', F\lastIndexOf()], |
|
110 | - ['lastIndexOf', 'String -> String -> Number', F\lastIndexOf()], |
|
111 | - ['uniqueBy', 'Function -> List -> List', F\uniqueBy()], |
|
112 | - ['unique', 'List -> List', F\unique()], |
|
113 | - ['groupBy', 'Function -> List -> Object|Array', F\groupBy()], |
|
114 | - ['pairsFrom', 'List -> List -> List', F\pairsFrom()], |
|
115 | - ['sort', 'Function -> List -> List', F\sort()], |
|
116 | - ['plus', 'Number -> Number -> Number', F\plus()], |
|
117 | - ['minus', 'Number -> Number -> Number', F\minus()], |
|
118 | - ['negate', 'Number -> Number', F\negate()], |
|
119 | - ['multiply', 'Number -> Number -> Number', F\multiply()], |
|
120 | - ['divide', 'Number -> Number -> Number', F\divide()], |
|
121 | - ['modulo', 'Number -> Number -> Number', F\modulo()], |
|
122 | - ['sum', 'List -> Number', F\sum()], |
|
123 | - ['product', 'List -> Number', F\product()], |
|
124 | - ['min', 'Number -> Number -> Number', F\min()], |
|
125 | - ['minBy', 'Function -> Any -> Any -> Any', F\minBy()], |
|
126 | - ['max', 'Number -> Number -> Number', F\max()], |
|
127 | - ['maxBy', 'Function -> Any -> Any -> Any', F\maxBy()], |
|
6 | + ['then', 'Function -> Any -> Any', F\_f('_stream_then')], |
|
7 | + ['and', 'Boolean -> Boolean -> Boolean', F\and_()], |
|
8 | + ['or', 'Boolean -> Boolean -> Boolean', F\or_()], |
|
9 | + ['not', 'Boolean -> Boolean', F\not()], |
|
10 | + ['eq', 'Any -> Any -> Boolean', F\eq()], |
|
11 | + ['notEq', 'Any -> Any -> Boolean', F\notEq()], |
|
12 | + ['eqq', 'Any -> Any -> Boolean', F\eqq()], |
|
13 | + ['notEqq', 'Any -> Any -> Boolean', F\notEqq()], |
|
14 | + ['equals', 'Any -> Any -> Boolean', F\equals()], |
|
15 | + ['equalBy', 'Function -> Any -> Any -> Boolean', F\equalBy()], |
|
16 | + ['lt', 'Any -> Any -> Boolean', F\lt()], |
|
17 | + ['lte', 'Any -> Any -> Boolean', F\lte()], |
|
18 | + ['gt', 'Any -> Any -> Boolean', F\gt()], |
|
19 | + ['gte', 'Any -> Any -> Boolean', F\gte()], |
|
20 | + ['is', 'String -> Any -> Boolean', F\is()], |
|
21 | + ['toString', 'Any -> String', F\toString()], |
|
22 | + ['attributes', 'Object|Array -> Object|Array', F\attributes()], |
|
23 | + ['keys', 'List -> List', F\keys()], |
|
24 | + ['keys', 'Object|Array -> List', F\keys()], |
|
25 | + ['values', 'List -> List', F\values()], |
|
26 | + ['values', 'Object|Array -> List', F\values()], |
|
27 | + ['has', 'Any -> Object|Array -> Boolean', F\has()], |
|
28 | + ['get', 'Any -> Object|Array -> Any', F\get()], |
|
29 | + ['getPath', 'List -> Object|Array -> Any', F\getPath()], |
|
30 | + ['set', 'Any -> Any -> Object|Array -> Object|Array', F\set()], |
|
31 | + ['update', 'Any -> Function -> Object|Array -> Object|Array', F\update()], |
|
32 | + ['satisfies', 'Function -> Any -> Object|Array -> Boolean', F\satisfies()], |
|
33 | + ['satisfiesAll', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAll()], |
|
34 | + ['satisfiesAny', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAny()], |
|
35 | + ['toPairs', 'Object|Array -> List', F\toPairs()], |
|
36 | + ['toPairs', 'List -> List', F\toPairs()], |
|
37 | + ['split', 'String -> String -> List', F\split()], |
|
38 | + ['join', 'String -> List -> String', F\join()], |
|
39 | + ['replace', 'String|List -> String|List -> String -> String', F\replace()], |
|
40 | + ['regReplace', 'String -> String -> String -> String', F\regReplace()], |
|
41 | + ['upperCase', 'String -> String', F\upperCase()], |
|
42 | + ['lowerCase', 'String -> String', F\lowerCase()], |
|
43 | + ['camelCase', 'String -> String', F\camelCase()], |
|
44 | + ['snakeCase', 'String -> String -> String', F\snakeCase()], |
|
45 | + ['startsWith', 'String -> String -> Boolean', F\startsWith()], |
|
46 | + ['endsWith', 'String -> String -> Boolean', F\endsWith()], |
|
47 | + ['test', 'String -> String -> Boolean', F\test()], |
|
48 | + ['match', 'String -> String -> List', F\match()], |
|
49 | + ['occurences', 'String -> String -> Number', F\occurences()], |
|
50 | + ['chunks', 'String -> String -> String -> List', F\chunks()], |
|
51 | + ['map', 'Function -> List -> List', F\map()], |
|
52 | + ['map', 'Function -> Object|Array -> Object|Array', F\map()], |
|
53 | + ['chain', 'Function -> List -> List', F\chain()], |
|
54 | + ['filter', 'Function -> List -> List', F\filter()], |
|
55 | + ['reduce', 'Function -> Any -> List -> Any', F\reduce()], |
|
56 | + ['each', 'Function -> List -> List', F\each()], |
|
57 | + ['head', 'List -> Any', F\head()], |
|
58 | + ['head', 'String -> String', F\head()], |
|
59 | + ['last', 'List -> Any', F\last()], |
|
60 | + ['last', 'String -> String', F\last()], |
|
61 | + ['init', 'List -> Any', F\init()], |
|
62 | + ['init', 'String -> String', F\init()], |
|
63 | + ['tail', 'List -> Any', F\tail()], |
|
64 | + ['tail', 'String -> String', F\tail()], |
|
65 | + ['reverse', 'List -> List', F\reverse()], |
|
66 | + ['reverse', 'String -> String', F\reverse()], |
|
67 | + ['length', 'List -> Number', F\length()], |
|
68 | + ['length', 'String -> Number', F\length()], |
|
69 | + ['allSatisfies', 'Function -> List -> Boolean', F\allSatisfies()], |
|
70 | + ['anySatisfies', 'Function -> List -> Boolean', F\anySatisfies()], |
|
71 | + ['concat', 'List -> List -> List', F\concat()], |
|
72 | + ['concat', 'String -> String -> String', F\concat()], |
|
73 | + ['concatAll', 'List -> List', F\concatAll()], |
|
74 | + ['insert', 'Number -> Any -> List -> List', F\insert()], |
|
75 | + ['insert', 'Number -> String -> String -> String', F\insert()], |
|
76 | + ['insertAll', 'Number -> List -> List -> List', F\insertAll()], |
|
77 | + ['insertAll', 'Number -> String -> String -> String', F\insertAll()], |
|
78 | + ['append', 'Any -> List -> List', F\append()], |
|
79 | + ['append', 'String -> String -> String', F\append()], |
|
80 | + ['prepend', 'Any -> List -> List', F\prepend()], |
|
81 | + ['prepend', 'String -> String -> String', F\prepend()], |
|
82 | + ['take', 'Number -> List -> List', F\take()], |
|
83 | + ['take', 'Number -> String -> String', F\take()], |
|
84 | + ['takeWhile', 'Function -> List -> List', F\takeWhile()], |
|
85 | + ['takeLastWhile', 'Function -> List -> List', F\takeLastWhile()], |
|
86 | + ['takeUntil', 'Function -> List -> List', F\takeUntil()], |
|
87 | + ['takeLastUntil', 'Function -> List -> List', F\takeLastUntil()], |
|
88 | + ['remove', 'Number -> List -> List', F\remove()], |
|
89 | + ['remove', 'Number -> String -> String', F\remove()], |
|
90 | + ['removeWhile', 'Function -> List -> List', F\removeWhile()], |
|
91 | + ['removeLastWhile', 'Function -> List -> List', F\removeLastWhile()], |
|
92 | + ['removeUntil', 'Function -> List -> List', F\removeUntil()], |
|
93 | + ['removeLastUntil', 'Function -> List -> List', F\removeLastUntil()], |
|
94 | + ['fromPairs', 'List -> Object|Array', F\fromPairs()], |
|
95 | + ['slices', 'Number -> List -> List', F\slices()], |
|
96 | + ['slices', 'Number -> String -> List', F\slices()], |
|
97 | + ['contains', 'Any -> List -> Boolean', F\contains()], |
|
98 | + ['contains', 'String -> String -> Boolean', F\contains()], |
|
99 | + ['findIndex', 'Function -> List -> Number|Null', F\findIndex()], |
|
100 | + ['findIndex', 'Function -> Object|Array -> Any', F\findIndex()], |
|
101 | + ['findLastIndex', 'Function -> List -> Number|Null', F\findLastIndex()], |
|
102 | + ['findLastIndex', 'Function -> Object|Array -> Any', F\findLastIndex()], |
|
103 | + ['find', 'Function -> List -> Any', F\find()], |
|
104 | + ['findLast', 'Function -> List -> Any', F\findLast()], |
|
105 | + ['indexOf', 'Any -> List -> Number', F\indexOf()], |
|
106 | + ['indexOf', 'Any -> Object|Array -> Any', F\indexOf()], |
|
107 | + ['indexOf', 'String -> String -> Number', F\indexOf()], |
|
108 | + ['lastIndexOf', 'Any -> List -> Number', F\lastIndexOf()], |
|
109 | + ['lastIndexOf', 'Any -> Object|Array -> Any', F\lastIndexOf()], |
|
110 | + ['lastIndexOf', 'String -> String -> Number', F\lastIndexOf()], |
|
111 | + ['uniqueBy', 'Function -> List -> List', F\uniqueBy()], |
|
112 | + ['unique', 'List -> List', F\unique()], |
|
113 | + ['groupBy', 'Function -> List -> Object|Array', F\groupBy()], |
|
114 | + ['pairsFrom', 'List -> List -> List', F\pairsFrom()], |
|
115 | + ['sort', 'Function -> List -> List', F\sort()], |
|
116 | + ['plus', 'Number -> Number -> Number', F\plus()], |
|
117 | + ['minus', 'Number -> Number -> Number', F\minus()], |
|
118 | + ['negate', 'Number -> Number', F\negate()], |
|
119 | + ['multiply', 'Number -> Number -> Number', F\multiply()], |
|
120 | + ['divide', 'Number -> Number -> Number', F\divide()], |
|
121 | + ['modulo', 'Number -> Number -> Number', F\modulo()], |
|
122 | + ['sum', 'List -> Number', F\sum()], |
|
123 | + ['product', 'List -> Number', F\product()], |
|
124 | + ['min', 'Number -> Number -> Number', F\min()], |
|
125 | + ['minBy', 'Function -> Any -> Any -> Any', F\minBy()], |
|
126 | + ['max', 'Number -> Number -> Number', F\max()], |
|
127 | + ['maxBy', 'Function -> Any -> Any -> Any', F\maxBy()], |
|
128 | 128 | |
129 | 129 | ]); |
@@ -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 | }; |
@@ -119,25 +119,30 @@ discard block |
||
119 | 119 | return function() use($fn) { |
120 | 120 | $args = func_get_args(); |
121 | 121 | $n = count($args); |
122 | - while ($n > 0 && _is_placeholder($args[$n - 1])) |
|
123 | - $n --; |
|
124 | - if ($n == 0) |
|
125 | - return _curry_two($fn); |
|
122 | + while ($n > 0 && _is_placeholder($args[$n - 1])) { |
|
123 | + $n --; |
|
124 | + } |
|
125 | + if ($n == 0) { |
|
126 | + return _curry_two($fn); |
|
127 | + } |
|
126 | 128 | if ($n == 1) { |
127 | 129 | $a = &$args[0]; |
128 | - if (_is_placeholder($a)) |
|
129 | - return _curry_two($fn); |
|
130 | + if (_is_placeholder($a)) { |
|
131 | + return _curry_two($fn); |
|
132 | + } |
|
130 | 133 | return _curry_one(function($b) use($fn, &$a) { |
131 | 134 | return $fn($a, $b); |
132 | 135 | }); |
133 | 136 | } |
134 | 137 | $a = &$args[0]; |
135 | 138 | $b = &$args[1]; |
136 | - if (_is_placeholder($a) && _is_placeholder($b)) |
|
137 | - return _curry_two($fn); |
|
138 | - if (_is_placeholder($a)) |
|
139 | - return _curry_one(function($_a) use($fn, &$b) { |
|
139 | + if (_is_placeholder($a) && _is_placeholder($b)) { |
|
140 | + return _curry_two($fn); |
|
141 | + } |
|
142 | + if (_is_placeholder($a)) { |
|
143 | + return _curry_one(function($_a) use($fn, &$b) { |
|
140 | 144 | return $fn($_a, $b); |
145 | + } |
|
141 | 146 | }); |
142 | 147 | return $fn($args[0], $args[1]); |
143 | 148 | }; |
@@ -168,10 +173,12 @@ discard block |
||
168 | 173 | return function() use($fn) { |
169 | 174 | $args = func_get_args(); |
170 | 175 | $n = count($args); |
171 | - while ($n > 0 && _is_placeholder($args[$n - 1])) |
|
172 | - $n --; |
|
173 | - if ($n == 0) |
|
174 | - return _curry_three($fn); |
|
176 | + while ($n > 0 && _is_placeholder($args[$n - 1])) { |
|
177 | + $n --; |
|
178 | + } |
|
179 | + if ($n == 0) { |
|
180 | + return _curry_three($fn); |
|
181 | + } |
|
175 | 182 | if ($n == 1) { |
176 | 183 | $a = &$args[0]; |
177 | 184 | return _curry_two(function($b, $c) use($fn, &$a) { |
@@ -181,9 +188,10 @@ discard block |
||
181 | 188 | if ($n == 2) { |
182 | 189 | $a = &$args[0]; $b = &$args[1]; |
183 | 190 | |
184 | - if (_is_placeholder($a)) |
|
185 | - return _curry_two(function($_a, $c) use($fn, &$b) { |
|
191 | + if (_is_placeholder($a)) { |
|
192 | + return _curry_two(function($_a, $c) use($fn, &$b) { |
|
186 | 193 | return $fn($_a, $b, $c); |
194 | + } |
|
187 | 195 | }); |
188 | 196 | return _curry_one(function($c) use($fn, &$a, &$b) { |
189 | 197 | return $fn($a, $b, $c); |
@@ -192,17 +200,20 @@ discard block |
||
192 | 200 | |
193 | 201 | $a = &$args[0]; $b = &$args[1]; $c = &$args[2]; |
194 | 202 | |
195 | - if (_is_placeholder($a) && _is_placeholder($b)) |
|
196 | - return _curry_two(function($_a, $_b) use($fn, &$c) { |
|
203 | + if (_is_placeholder($a) && _is_placeholder($b)) { |
|
204 | + return _curry_two(function($_a, $_b) use($fn, &$c) { |
|
197 | 205 | return $fn($_a, $_b, $c); |
206 | + } |
|
198 | 207 | }); |
199 | - if (_is_placeholder($a)) |
|
200 | - return _curry_one(function($_a) use($fn, &$b, &$c) { |
|
208 | + if (_is_placeholder($a)) { |
|
209 | + return _curry_one(function($_a) use($fn, &$b, &$c) { |
|
201 | 210 | return $fn($_a, $b, $c); |
211 | + } |
|
202 | 212 | }); |
203 | - if (_is_placeholder($b)) |
|
204 | - return _curry_one(function($_b) use($fn, &$a, &$c) { |
|
213 | + if (_is_placeholder($b)) { |
|
214 | + return _curry_one(function($_b) use($fn, &$a, &$c) { |
|
205 | 215 | return $fn($a, $_b, $c); |
216 | + } |
|
206 | 217 | }); |
207 | 218 | |
208 | 219 | return $fn($a, $b, $c); |
@@ -284,8 +295,9 @@ discard block |
||
284 | 295 | $merged->args[$mergedIndex] = $given[$givenIndex]; |
285 | 296 | } |
286 | 297 | |
287 | - if (_is_placeholder($merged->args[$mergedIndex])) |
|
288 | - $merged->placeholders ++; |
|
298 | + if (_is_placeholder($merged->args[$mergedIndex])) { |
|
299 | + $merged->placeholders ++; |
|
300 | + } |
|
289 | 301 | |
290 | 302 | $givenIndex ++; |
291 | 303 | $mergedIndex ++; |
@@ -303,8 +315,9 @@ discard block |
||
303 | 315 | $argsCount = count($args); |
304 | 316 | $fillersCount = count($fillers); |
305 | 317 | while ($fillersIndex < $fillersCount) { |
306 | - while (!_is_placeholder($args[$argsIndex])) |
|
307 | - $argsIndex ++; |
|
318 | + while (!_is_placeholder($args[$argsIndex])) { |
|
319 | + $argsIndex ++; |
|
320 | + } |
|
308 | 321 | $args[$argsIndex] = $fillers[$fillersIndex]; |
309 | 322 | $fillersIndex ++; |
310 | 323 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @ignore |
89 | 89 | * @signature (a -> b) -> (a -> b) |
90 | 90 | * @param callable $fn |
91 | - * @return callable |
|
91 | + * @return \Closure |
|
92 | 92 | */ |
93 | 93 | function _curry_one($fn) { |
94 | 94 | return function() use($fn) { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @signature (a,b -> c) -> (a -> b -> c) |
115 | 115 | * @param callable $fn |
116 | - * @return callable |
|
116 | + * @return \Closure |
|
117 | 117 | */ |
118 | 118 | function _curry_two($fn) { |
119 | 119 | return function() use($fn) { |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @signature (a,b,c -> d) -> (a -> b -> c -> d) |
166 | 166 | * @param callable $fn |
167 | - * @return callable |
|
167 | + * @return \Closure |
|
168 | 168 | */ |
169 | 169 | function _curry_three($fn) { |
170 | 170 | return function() use($fn) { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param callable $fn |
228 | 228 | * @param int $n |
229 | 229 | * @param array $given |
230 | - * @return callable |
|
230 | + * @return \Closure |
|
231 | 231 | */ |
232 | 232 | function _curry_n($fn, $n, $given = []) { |
233 | 233 | return function() use($fn, $n, $given) { |
@@ -314,11 +314,11 @@ |
||
314 | 314 | } |
315 | 315 | |
316 | 316 | function _iterable_reduce(callable $reducer, $acc, \Iterator $iterator) { |
317 | - $iterator->rewind(); |
|
318 | - while ($iterator->valid()) { |
|
319 | - $acc = $reducer($acc, $iterator->current(), $iterator->key()); |
|
320 | - $iterator->next(); |
|
321 | - } |
|
322 | - return $acc; |
|
317 | + $iterator->rewind(); |
|
318 | + while ($iterator->valid()) { |
|
319 | + $acc = $reducer($acc, $iterator->current(), $iterator->key()); |
|
320 | + $iterator->next(); |
|
321 | + } |
|
322 | + return $acc; |
|
323 | 323 | } |
324 | 324 |
@@ -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; |
@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | $words = []; |
8 | 8 | foreach ($text as $word => $occ) { |
9 | - if (! isset($words[$occ])) { |
|
9 | + if (!isset($words[$occ])) { |
|
10 | 10 | $words[$occ] = []; |
11 | 11 | } |
12 | 12 | $words[$occ][] = $word; |
@@ -103,8 +103,9 @@ |
||
103 | 103 | protected function getWordsHavingOccurrences($number) { |
104 | 104 | $result = []; |
105 | 105 | foreach ($this->list as $word) { |
106 | - if ($word->occurrences() == $number) |
|
107 | - $result[] = $word; |
|
106 | + if ($word->occurrences() == $number) { |
|
107 | + $result[] = $word; |
|
108 | + } |
|
108 | 109 | } |
109 | 110 | usort($result, function(Word $w1, Word $w2) { |
110 | 111 | return strcmp($w1->value(), $w2->value()); |
@@ -8,10 +8,10 @@ |
||
8 | 8 | */ |
9 | 9 | class Placeholder { |
10 | 10 | private static $instance; |
11 | - private function __construct(){} |
|
11 | + private function __construct() {} |
|
12 | 12 | public static function get() |
13 | 13 | { |
14 | - if(static::$instance === null) |
|
14 | + if (static::$instance === null) |
|
15 | 15 | static::$instance = new Placeholder; |
16 | 16 | return static::$instance; |
17 | 17 | } |
@@ -11,8 +11,9 @@ |
||
11 | 11 | private function __construct(){} |
12 | 12 | public static function get() |
13 | 13 | { |
14 | - if(static::$instance === null) |
|
15 | - static::$instance = new Placeholder; |
|
14 | + if(static::$instance === null) { |
|
15 | + static::$instance = new Placeholder; |
|
16 | + } |
|
16 | 17 | return static::$instance; |
17 | 18 | } |
18 | 19 | } |
@@ -82,8 +82,6 @@ discard block |
||
82 | 82 | * ``` |
83 | 83 | * |
84 | 84 | * @signature (*... -> a) -> [*] -> a |
85 | - * @param callable $fn |
|
86 | - * @param array $args |
|
87 | 85 | * @return mixed |
88 | 86 | */ |
89 | 87 | function apply() { |
@@ -107,7 +105,6 @@ discard block |
||
107 | 105 | * ``` |
108 | 106 | * |
109 | 107 | * @signature (((a, b, ...) -> o), (o -> p), ..., (y -> z)) -> ((a, b, ...) -> z) |
110 | - * @param callable $fns... |
|
111 | 108 | * @return callable |
112 | 109 | */ |
113 | 110 | function pipe() { |
@@ -138,7 +135,6 @@ discard block |
||
138 | 135 | * ``` |
139 | 136 | * |
140 | 137 | * @signature (((a, b, ...) -> o), (o -> p), ..., (y -> z)) -> ((a, b, ...) -> z) |
141 | - * @param callable $fns... |
|
142 | 138 | * @return callable |
143 | 139 | */ |
144 | 140 | function compose() { |
@@ -186,7 +182,6 @@ discard block |
||
186 | 182 | * ``` |
187 | 183 | * |
188 | 184 | * @signature a -> (* -> a) |
189 | - * @param mixed $value |
|
190 | 185 | * @return callable |
191 | 186 | */ |
192 | 187 | function give() { |
@@ -215,7 +210,6 @@ discard block |
||
215 | 210 | * ``` |
216 | 211 | * |
217 | 212 | * @signature ((a -> Boolean), ..., (a -> Boolean)) -> (a -> Boolean) |
218 | - * @param callable $predicates... |
|
219 | 213 | * @return callable |
220 | 214 | */ |
221 | 215 | function all() { |
@@ -249,7 +243,6 @@ discard block |
||
249 | 243 | * ``` |
250 | 244 | * |
251 | 245 | * @signature ((a -> Boolean), ..., (a -> Boolean)) -> (a -> Boolean) |
252 | - * @param callable $predicates... |
|
253 | 246 | * @return callable |
254 | 247 | */ |
255 | 248 | function any() { |
@@ -280,7 +273,6 @@ discard block |
||
280 | 273 | * ``` |
281 | 274 | * |
282 | 275 | * @signature (* -> ... -> *) -> (* -> ... -> Boolean) |
283 | - * @param callable $fn |
|
284 | 276 | * @return callable |
285 | 277 | */ |
286 | 278 | function complement() { |
@@ -313,7 +305,6 @@ discard block |
||
313 | 305 | * ``` |
314 | 306 | * |
315 | 307 | * @signature (a -> a -> Boolean) -> (a -> a -> Number) |
316 | - * @param callable $fn |
|
317 | 308 | * @return callable |
318 | 309 | */ |
319 | 310 | function comparator() { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | function curry($fn) { |
39 | 39 | $n = _number_of_args($fn); |
40 | - switch($n) { |
|
40 | + switch ($n) { |
|
41 | 41 | case 0: return $fn; |
42 | 42 | case 1: return _curry_one($fn); |
43 | 43 | case 2: return _curry_two($fn); |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | */ |
113 | 113 | function pipe() { |
114 | 114 | $fns = func_get_args(); |
115 | - if(count($fns) < 1) |
|
115 | + if (count($fns) < 1) |
|
116 | 116 | return identity(); |
117 | - return function () use ($fns) { |
|
117 | + return function() use ($fns) { |
|
118 | 118 | $result = _apply(array_shift($fns), func_get_args()); |
119 | 119 | foreach ($fns as $fn) { |
120 | 120 | $result = $fn($result); |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | */ |
144 | 144 | function compose() { |
145 | 145 | $fns = array_reverse(func_get_args()); |
146 | - if(count($fns) < 1) |
|
146 | + if (count($fns) < 1) |
|
147 | 147 | return identity(); |
148 | - return function () use ($fns) { |
|
148 | + return function() use ($fns) { |
|
149 | 149 | $result = _apply(array_shift($fns), func_get_args()); |
150 | 150 | foreach ($fns as $fn) { |
151 | 151 | $result = $fn($result); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $predicates = func_get_args(); |
223 | 223 | return _curry_one(function($value) use(&$predicates) { |
224 | 224 | foreach ($predicates as $predicate) { |
225 | - if (! $predicate($value)) |
|
225 | + if (!$predicate($value)) |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | return true; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | static $comparator = false; |
321 | 321 | $comparator = $comparator ?: curry(function($fn) { |
322 | 322 | return function($a, $b) use($fn) { |
323 | - if ($fn($a, $b)) return -1; |
|
323 | + if ($fn($a, $b)) return - 1; |
|
324 | 324 | if ($fn($b, $a)) return 1; |
325 | 325 | return 0; |
326 | 326 | }; |
@@ -112,8 +112,9 @@ discard block |
||
112 | 112 | */ |
113 | 113 | function pipe() { |
114 | 114 | $fns = func_get_args(); |
115 | - if(count($fns) < 1) |
|
116 | - return identity(); |
|
115 | + if(count($fns) < 1) { |
|
116 | + return identity(); |
|
117 | + } |
|
117 | 118 | return function () use ($fns) { |
118 | 119 | $result = _apply(array_shift($fns), func_get_args()); |
119 | 120 | foreach ($fns as $fn) { |
@@ -143,8 +144,9 @@ discard block |
||
143 | 144 | */ |
144 | 145 | function compose() { |
145 | 146 | $fns = array_reverse(func_get_args()); |
146 | - if(count($fns) < 1) |
|
147 | - return identity(); |
|
147 | + if(count($fns) < 1) { |
|
148 | + return identity(); |
|
149 | + } |
|
148 | 150 | return function () use ($fns) { |
149 | 151 | $result = _apply(array_shift($fns), func_get_args()); |
150 | 152 | foreach ($fns as $fn) { |
@@ -222,8 +224,9 @@ discard block |
||
222 | 224 | $predicates = func_get_args(); |
223 | 225 | return _curry_one(function($value) use(&$predicates) { |
224 | 226 | foreach ($predicates as $predicate) { |
225 | - if (! $predicate($value)) |
|
226 | - return false; |
|
227 | + if (! $predicate($value)) { |
|
228 | + return false; |
|
229 | + } |
|
227 | 230 | } |
228 | 231 | return true; |
229 | 232 | }); |
@@ -256,8 +259,9 @@ discard block |
||
256 | 259 | $predicates = func_get_args(); |
257 | 260 | return _curry_one(function($value) use(&$predicates) { |
258 | 261 | foreach ($predicates as $predicate) { |
259 | - if ($predicate($value)) |
|
260 | - return true; |
|
262 | + if ($predicate($value)) { |
|
263 | + return true; |
|
264 | + } |
|
261 | 265 | } |
262 | 266 | return false; |
263 | 267 | }); |
@@ -320,8 +324,12 @@ discard block |
||
320 | 324 | static $comparator = false; |
321 | 325 | $comparator = $comparator ?: curry(function($fn) { |
322 | 326 | return function($a, $b) use($fn) { |
323 | - if ($fn($a, $b)) return -1; |
|
324 | - if ($fn($b, $a)) return 1; |
|
327 | + if ($fn($a, $b)) { |
|
328 | + return -1; |
|
329 | + } |
|
330 | + if ($fn($b, $a)) { |
|
331 | + return 1; |
|
332 | + } |
|
325 | 333 | return 0; |
326 | 334 | }; |
327 | 335 | }); |
@@ -13,66 +13,66 @@ |
||
13 | 13 | */ |
14 | 14 | class _IteratorAdapter implements \Iterator |
15 | 15 | { |
16 | - private $objectStorage; |
|
16 | + private $objectStorage; |
|
17 | 17 | |
18 | - public function __construct(\SplObjectStorage $theObjectStorage) |
|
19 | - { |
|
20 | - $this->objectStorage = $theObjectStorage; |
|
21 | - } |
|
18 | + public function __construct(\SplObjectStorage $theObjectStorage) |
|
19 | + { |
|
20 | + $this->objectStorage = $theObjectStorage; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Return the current element |
|
25 | - * @link http://php.net/manual/en/iterator.current.php |
|
26 | - * @return mixed Can return any type. |
|
27 | - * @since 5.0.0 |
|
28 | - */ |
|
29 | - public function current() |
|
30 | - { |
|
31 | - return $this->objectStorage->getInfo(); |
|
32 | - } |
|
23 | + /** |
|
24 | + * Return the current element |
|
25 | + * @link http://php.net/manual/en/iterator.current.php |
|
26 | + * @return mixed Can return any type. |
|
27 | + * @since 5.0.0 |
|
28 | + */ |
|
29 | + public function current() |
|
30 | + { |
|
31 | + return $this->objectStorage->getInfo(); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Move forward to next element |
|
36 | - * @link http://php.net/manual/en/iterator.next.php |
|
37 | - * @return void Any returned value is ignored. |
|
38 | - * @since 5.0.0 |
|
39 | - */ |
|
40 | - public function next() |
|
41 | - { |
|
42 | - return $this->objectStorage->next(); |
|
43 | - } |
|
34 | + /** |
|
35 | + * Move forward to next element |
|
36 | + * @link http://php.net/manual/en/iterator.next.php |
|
37 | + * @return void Any returned value is ignored. |
|
38 | + * @since 5.0.0 |
|
39 | + */ |
|
40 | + public function next() |
|
41 | + { |
|
42 | + return $this->objectStorage->next(); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Return the key of the current element |
|
47 | - * @link http://php.net/manual/en/iterator.key.php |
|
48 | - * @return mixed scalar on success, or null on failure. |
|
49 | - * @since 5.0.0 |
|
50 | - */ |
|
51 | - public function key() |
|
52 | - { |
|
53 | - return $this->objectStorage->current(); |
|
54 | - } |
|
45 | + /** |
|
46 | + * Return the key of the current element |
|
47 | + * @link http://php.net/manual/en/iterator.key.php |
|
48 | + * @return mixed scalar on success, or null on failure. |
|
49 | + * @since 5.0.0 |
|
50 | + */ |
|
51 | + public function key() |
|
52 | + { |
|
53 | + return $this->objectStorage->current(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Checks if current position is valid |
|
58 | - * @link http://php.net/manual/en/iterator.valid.php |
|
59 | - * @return boolean The return value will be casted to boolean and then evaluated. |
|
60 | - * Returns true on success or false on failure. |
|
61 | - * @since 5.0.0 |
|
62 | - */ |
|
63 | - public function valid() |
|
64 | - { |
|
65 | - return $this->objectStorage->valid(); |
|
66 | - } |
|
56 | + /** |
|
57 | + * Checks if current position is valid |
|
58 | + * @link http://php.net/manual/en/iterator.valid.php |
|
59 | + * @return boolean The return value will be casted to boolean and then evaluated. |
|
60 | + * Returns true on success or false on failure. |
|
61 | + * @since 5.0.0 |
|
62 | + */ |
|
63 | + public function valid() |
|
64 | + { |
|
65 | + return $this->objectStorage->valid(); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Rewind the Iterator to the first element |
|
70 | - * @link http://php.net/manual/en/iterator.rewind.php |
|
71 | - * @return void Any returned value is ignored. |
|
72 | - * @since 5.0.0 |
|
73 | - */ |
|
74 | - public function rewind() |
|
75 | - { |
|
76 | - return $this->objectStorage->rewind(); |
|
77 | - } |
|
68 | + /** |
|
69 | + * Rewind the Iterator to the first element |
|
70 | + * @link http://php.net/manual/en/iterator.rewind.php |
|
71 | + * @return void Any returned value is ignored. |
|
72 | + * @since 5.0.0 |
|
73 | + */ |
|
74 | + public function rewind() |
|
75 | + { |
|
76 | + return $this->objectStorage->rewind(); |
|
77 | + } |
|
78 | 78 | } |
79 | 79 | \ No newline at end of file |
@@ -73,35 +73,35 @@ discard block |
||
73 | 73 | function filter() { |
74 | 74 | static $filter = false; |
75 | 75 | $filter = $filter ?: curry(function(callable $fn, $list) { |
76 | - $isArray = is_array($list); |
|
77 | - $isObjectStorage = $list instanceof \SplObjectStorage; |
|
76 | + $isArray = is_array($list); |
|
77 | + $isObjectStorage = $list instanceof \SplObjectStorage; |
|
78 | 78 | |
79 | - $result = $isArray ? [] |
|
80 | - : ($isObjectStorage ? new \SplObjectStorage() |
|
81 | - : new \ArrayObject()); |
|
79 | + $result = $isArray ? [] |
|
80 | + : ($isObjectStorage ? new \SplObjectStorage() |
|
81 | + : new \ArrayObject()); |
|
82 | 82 | |
83 | - if ($isArray) |
|
84 | - { |
|
85 | - foreach ($list as $item) { |
|
86 | - if ($fn($item)) |
|
87 | - $result[] = $item; |
|
88 | - } |
|
89 | - return $result; |
|
90 | - } |
|
83 | + if ($isArray) |
|
84 | + { |
|
85 | + foreach ($list as $item) { |
|
86 | + if ($fn($item)) |
|
87 | + $result[] = $item; |
|
88 | + } |
|
89 | + return $result; |
|
90 | + } |
|
91 | 91 | |
92 | - return _iterable_reduce( |
|
93 | - _make_filterer($isObjectStorage ? |
|
94 | - function(\ArrayAccess $xs, $value) { |
|
95 | - $xs->offsetSet($value); |
|
96 | - } : |
|
97 | - function(\ArrayObject $xs, $value) { |
|
98 | - $xs->append($value); |
|
99 | - }, |
|
100 | - $fn |
|
101 | - ), |
|
102 | - $result, |
|
103 | - $isObjectStorage ? $list : $list->getIterator() |
|
104 | - ); |
|
92 | + return _iterable_reduce( |
|
93 | + _make_filterer($isObjectStorage ? |
|
94 | + function(\ArrayAccess $xs, $value) { |
|
95 | + $xs->offsetSet($value); |
|
96 | + } : |
|
97 | + function(\ArrayObject $xs, $value) { |
|
98 | + $xs->append($value); |
|
99 | + }, |
|
100 | + $fn |
|
101 | + ), |
|
102 | + $result, |
|
103 | + $isObjectStorage ? $list : $list->getIterator() |
|
104 | + ); |
|
105 | 105 | }); |
106 | 106 | return _apply($filter, func_get_args()); |
107 | 107 | } |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | * @return \Closure |
114 | 114 | */ |
115 | 115 | function _make_filterer (callable $append, callable $predicate) { |
116 | - return function ($acc, ...$entry) use ($append, $predicate) { |
|
117 | - if ($predicate($entry[0])) { |
|
118 | - $append($acc, ...$entry); |
|
119 | - } |
|
120 | - return $acc; |
|
121 | - }; |
|
116 | + return function ($acc, ...$entry) use ($append, $predicate) { |
|
117 | + if ($predicate($entry[0])) { |
|
118 | + $append($acc, ...$entry); |
|
119 | + } |
|
120 | + return $acc; |
|
121 | + }; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -155,30 +155,30 @@ discard block |
||
155 | 155 | * @return array|\ArrayObject|\SplObjectStorage|callable |
156 | 156 | */ |
157 | 157 | function filter_values() { |
158 | - static $filter_values = false; |
|
158 | + static $filter_values = false; |
|
159 | 159 | $filter_values = $filter_values ?: curry(function(callable $predicate, $list) { |
160 | - $isArray = is_array($list); |
|
161 | - $isObjectStorage = $list instanceof \SplObjectStorage; |
|
160 | + $isArray = is_array($list); |
|
161 | + $isObjectStorage = $list instanceof \SplObjectStorage; |
|
162 | 162 | |
163 | - $result = $isArray ? [] |
|
164 | - : ($isObjectStorage ? new \SplObjectStorage() |
|
165 | - : new \ArrayObject()); |
|
163 | + $result = $isArray ? [] |
|
164 | + : ($isObjectStorage ? new \SplObjectStorage() |
|
165 | + : new \ArrayObject()); |
|
166 | 166 | |
167 | - return _iterable_reduce( |
|
168 | - _make_filterer($isArray ? |
|
169 | - function(array &$xs, $value, $key) { |
|
170 | - $xs[$key] = $value; |
|
171 | - } : |
|
172 | - function(\ArrayAccess $xs, $value, $key) { |
|
173 | - $xs->offsetSet($key, $value); |
|
174 | - }, |
|
175 | - $predicate |
|
176 | - ), |
|
177 | - $result, |
|
178 | - $isArray ? new \ArrayIterator($list) |
|
179 | - : ($isObjectStorage ? new _IteratorAdapter($list) |
|
180 | - : $list->getIterator()) |
|
181 | - ); |
|
167 | + return _iterable_reduce( |
|
168 | + _make_filterer($isArray ? |
|
169 | + function(array &$xs, $value, $key) { |
|
170 | + $xs[$key] = $value; |
|
171 | + } : |
|
172 | + function(\ArrayAccess $xs, $value, $key) { |
|
173 | + $xs->offsetSet($key, $value); |
|
174 | + }, |
|
175 | + $predicate |
|
176 | + ), |
|
177 | + $result, |
|
178 | + $isArray ? new \ArrayIterator($list) |
|
179 | + : ($isObjectStorage ? new _IteratorAdapter($list) |
|
180 | + : $list->getIterator()) |
|
181 | + ); |
|
182 | 182 | }); |
183 | 183 | return _apply($filter_values, func_get_args()); |
184 | 184 | } |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param callable $predicate the filter function |
113 | 113 | * @return \Closure |
114 | 114 | */ |
115 | -function _make_filterer (callable $append, callable $predicate) { |
|
116 | - return function ($acc, ...$entry) use ($append, $predicate) { |
|
115 | +function _make_filterer(callable $append, callable $predicate) { |
|
116 | + return function($acc, ...$entry) use ($append, $predicate) { |
|
117 | 117 | if ($predicate($entry[0])) { |
118 | 118 | $append($acc, ...$entry); |
119 | 119 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | */ |
203 | 203 | function reduce() { |
204 | 204 | static $reduce = false; |
205 | - $reduce = $reduce ?: curry(function($fn, $initial, $list){ |
|
205 | + $reduce = $reduce ?: curry(function($fn, $initial, $list) { |
|
206 | 206 | return array_reduce($list, $fn, $initial); |
207 | 207 | }); |
208 | 208 | return _apply($reduce, func_get_args()); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | function each() { |
231 | 231 | static $each = false; |
232 | - $each = $each ?: curry(function($fn, $list){ |
|
232 | + $each = $each ?: curry(function($fn, $list) { |
|
233 | 233 | foreach ($list as $item) { |
234 | 234 | $fn($item); |
235 | 235 | } |
@@ -279,10 +279,10 @@ discard block |
||
279 | 279 | * @param array|string $list |
280 | 280 | * @return mixed |
281 | 281 | */ |
282 | -function last () { |
|
282 | +function last() { |
|
283 | 283 | static $last = false; |
284 | 284 | $last = $last ?: curry(function($list) { |
285 | - if(is_string($list)) |
|
285 | + if (is_string($list)) |
|
286 | 286 | return substr($list, -1); |
287 | 287 | $size = count($list); |
288 | 288 | return ($size > 0) |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | * @param array|string $list |
310 | 310 | * @return array |
311 | 311 | */ |
312 | -function init () { |
|
312 | +function init() { |
|
313 | 313 | static $init = false; |
314 | 314 | $init = $init ?: curry(function($list) { |
315 | - if(is_string($list)) { |
|
315 | + if (is_string($list)) { |
|
316 | 316 | $size = strlen($list); |
317 | 317 | return ($size > 1) |
318 | 318 | ? substr($list, 0, $size - 1) |
@@ -343,10 +343,10 @@ discard block |
||
343 | 343 | * @param array|string $list |
344 | 344 | * @return array |
345 | 345 | */ |
346 | -function tail () { |
|
346 | +function tail() { |
|
347 | 347 | static $tail = false; |
348 | 348 | $tail = $tail ?: curry(function($list) { |
349 | - if(is_string($list)) |
|
349 | + if (is_string($list)) |
|
350 | 350 | return (strlen($list) > 1) |
351 | 351 | ? substr($list, 1) |
352 | 352 | : ''; |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @param array|string $list |
372 | 372 | * @return array |
373 | 373 | */ |
374 | -function reverse () { |
|
374 | +function reverse() { |
|
375 | 375 | static $reverse = false; |
376 | 376 | $reverse = $reverse ?: curry(function($list) { |
377 | 377 | return is_string($list) |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | static $allSatisfies = false; |
425 | 425 | $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) { |
426 | 426 | foreach ($list as $item) { |
427 | - if (! $predicate($item)) |
|
427 | + if (!$predicate($item)) |
|
428 | 428 | return false; |
429 | 429 | } |
430 | 430 | return true; |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | */ |
601 | 601 | function append() { |
602 | 602 | static $append = false; |
603 | - $append = $append ?: curry(function ($item, $list) { |
|
603 | + $append = $append ?: curry(function($item, $list) { |
|
604 | 604 | return is_string($list) |
605 | 605 | ? $list . $item |
606 | 606 | : array_merge($list, [$item]); |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | */ |
627 | 627 | function prepend() { |
628 | 628 | static $prepend = false; |
629 | - $prepend = $prepend ?: curry(function ($item, $list) { |
|
629 | + $prepend = $prepend ?: curry(function($item, $list) { |
|
630 | 630 | return is_string($list) |
631 | 631 | ? $item . $list |
632 | 632 | : array_merge([$item], $list); |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | $length = length($list); |
662 | 662 | if ($count > $length || $count < -$length) |
663 | 663 | return $list; |
664 | - if(is_string($list)) { |
|
664 | + if (is_string($list)) { |
|
665 | 665 | return ($count >= 0) |
666 | 666 | ? substr($list, 0, $count) |
667 | 667 | : substr($list, $count); |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | $count = ($count > 0) |
813 | 813 | ? $count - $length |
814 | 814 | : $count + $length; |
815 | - if(is_string($list)) { |
|
815 | + if (is_string($list)) { |
|
816 | 816 | return ($count >= 0) |
817 | 817 | ? substr($list, 0, $count) |
818 | 818 | : substr($list, $count); |
@@ -1169,7 +1169,7 @@ discard block |
||
1169 | 1169 | $indexOf = $indexOf ?: curry(function($item, $list) { |
1170 | 1170 | if (is_string($list)) { |
1171 | 1171 | $index = strpos($list, $item); |
1172 | - return $index === false ? -1 : $index; |
|
1172 | + return $index === false ? - 1 : $index; |
|
1173 | 1173 | } |
1174 | 1174 | $list = (array) $list; |
1175 | 1175 | $index = 0; |
@@ -1180,7 +1180,7 @@ discard block |
||
1180 | 1180 | return $keys[$index]; |
1181 | 1181 | $index ++; |
1182 | 1182 | } |
1183 | - return -1; |
|
1183 | + return - 1; |
|
1184 | 1184 | }); |
1185 | 1185 | return _apply($indexOf, func_get_args()); |
1186 | 1186 | } |
@@ -1209,7 +1209,7 @@ discard block |
||
1209 | 1209 | $lastIndexOf = $lastIndexOf ?: curry(function($item, $list) { |
1210 | 1210 | if (is_string($list)) { |
1211 | 1211 | $index = strrpos($list, $item); |
1212 | - return $index === false ? -1 : $index; |
|
1212 | + return $index === false ? - 1 : $index; |
|
1213 | 1213 | } |
1214 | 1214 | $list = (array) $list; |
1215 | 1215 | $keys = array_keys($list); |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | return $keys[$index]; |
1220 | 1220 | $index --; |
1221 | 1221 | } |
1222 | - return -1; |
|
1222 | + return - 1; |
|
1223 | 1223 | }); |
1224 | 1224 | return _apply($lastIndexOf, func_get_args()); |
1225 | 1225 | } |
@@ -1254,7 +1254,7 @@ discard block |
||
1254 | 1254 | } |
1255 | 1255 | $index ++; |
1256 | 1256 | } |
1257 | - if (! $found) { |
|
1257 | + if (!$found) { |
|
1258 | 1258 | $result[$size] = $item; |
1259 | 1259 | $size ++; |
1260 | 1260 | } |
@@ -1314,9 +1314,9 @@ discard block |
||
1314 | 1314 | static $groupBy = false; |
1315 | 1315 | $groupBy = $groupBy ?: curry(function($fn, $list) { |
1316 | 1316 | $result = []; |
1317 | - foreach($list as $item) { |
|
1317 | + foreach ($list as $item) { |
|
1318 | 1318 | $index = $fn($item); |
1319 | - if (! isset($result[$index])) |
|
1319 | + if (!isset($result[$index])) |
|
1320 | 1320 | $result[$index] = []; |
1321 | 1321 | $result[$index][] = $item; |
1322 | 1322 | } |
@@ -83,8 +83,9 @@ discard block |
||
83 | 83 | if ($isArray) |
84 | 84 | { |
85 | 85 | foreach ($list as $item) { |
86 | - if ($fn($item)) |
|
87 | - $result[] = $item; |
|
86 | + if ($fn($item)) { |
|
87 | + $result[] = $item; |
|
88 | + } |
|
88 | 89 | } |
89 | 90 | return $result; |
90 | 91 | } |
@@ -257,7 +258,9 @@ discard block |
||
257 | 258 | function head() { |
258 | 259 | static $head = false; |
259 | 260 | $head = $head ?: curry(function($list) { |
260 | - if (isset($list[0])) return $list[0]; |
|
261 | + if (isset($list[0])) { |
|
262 | + return $list[0]; |
|
263 | + } |
|
261 | 264 | return is_string($list) ? '' : null; |
262 | 265 | }); |
263 | 266 | return _apply($head, func_get_args()); |
@@ -282,8 +285,9 @@ discard block |
||
282 | 285 | function last () { |
283 | 286 | static $last = false; |
284 | 287 | $last = $last ?: curry(function($list) { |
285 | - if(is_string($list)) |
|
286 | - return substr($list, -1); |
|
288 | + if(is_string($list)) { |
|
289 | + return substr($list, -1); |
|
290 | + } |
|
287 | 291 | $size = count($list); |
288 | 292 | return ($size > 0) |
289 | 293 | ? $list[$size - 1] |
@@ -346,10 +350,11 @@ discard block |
||
346 | 350 | function tail () { |
347 | 351 | static $tail = false; |
348 | 352 | $tail = $tail ?: curry(function($list) { |
349 | - if(is_string($list)) |
|
350 | - return (strlen($list) > 1) |
|
353 | + if(is_string($list)) { |
|
354 | + return (strlen($list) > 1) |
|
351 | 355 | ? substr($list, 1) |
352 | 356 | : ''; |
357 | + } |
|
353 | 358 | return (count($list) > 1) |
354 | 359 | ? array_slice($list, 1) |
355 | 360 | : []; |
@@ -424,8 +429,9 @@ discard block |
||
424 | 429 | static $allSatisfies = false; |
425 | 430 | $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) { |
426 | 431 | foreach ($list as $item) { |
427 | - if (! $predicate($item)) |
|
428 | - return false; |
|
432 | + if (! $predicate($item)) { |
|
433 | + return false; |
|
434 | + } |
|
429 | 435 | } |
430 | 436 | return true; |
431 | 437 | }); |
@@ -451,8 +457,9 @@ discard block |
||
451 | 457 | static $anySatisfies = false; |
452 | 458 | $anySatisfies = $anySatisfies ?: curry(function($predicate, $list) { |
453 | 459 | foreach ($list as $item) { |
454 | - if ($predicate($item)) |
|
455 | - return true; |
|
460 | + if ($predicate($item)) { |
|
461 | + return true; |
|
462 | + } |
|
456 | 463 | } |
457 | 464 | return false; |
458 | 465 | }); |
@@ -477,8 +484,9 @@ discard block |
||
477 | 484 | function concat() { |
478 | 485 | static $concat = false; |
479 | 486 | $concat = $concat ?: curry(function($list1, $list2) { |
480 | - if (is_string($list1) && is_string($list2)) |
|
481 | - return $list1 . $list2; |
|
487 | + if (is_string($list1) && is_string($list2)) { |
|
488 | + return $list1 . $list2; |
|
489 | + } |
|
482 | 490 | return array_merge($list1, $list2); |
483 | 491 | }); |
484 | 492 | return _apply($concat, func_get_args()); |
@@ -500,10 +508,12 @@ discard block |
||
500 | 508 | function concatAll() { |
501 | 509 | static $concatAll = false; |
502 | 510 | $concatAll = $concatAll ?: curry(function($lists) { |
503 | - if (count($lists) == 0) |
|
504 | - return []; |
|
505 | - if (is_string($lists[0])) |
|
506 | - return implode('', $lists); |
|
511 | + if (count($lists) == 0) { |
|
512 | + return []; |
|
513 | + } |
|
514 | + if (is_string($lists[0])) { |
|
515 | + return implode('', $lists); |
|
516 | + } |
|
507 | 517 | return _apply('array_merge', $lists); |
508 | 518 | }); |
509 | 519 | return _apply($concatAll, func_get_args()); |
@@ -568,14 +578,17 @@ discard block |
||
568 | 578 | static $insertAll = false; |
569 | 579 | $insertAll = $insertAll ?: curry(function($position, $items, $list) { |
570 | 580 | $size = length($list); |
571 | - if ($position < 0) |
|
572 | - $position = $size + $position; |
|
573 | - if ($position < 0) |
|
574 | - $position = 0; |
|
575 | - if (is_string($list)) |
|
576 | - return ($position >= $size) |
|
581 | + if ($position < 0) { |
|
582 | + $position = $size + $position; |
|
583 | + } |
|
584 | + if ($position < 0) { |
|
585 | + $position = 0; |
|
586 | + } |
|
587 | + if (is_string($list)) { |
|
588 | + return ($position >= $size) |
|
577 | 589 | ? $list . $items |
578 | 590 | : substr($list, 0, $position) . $items . substr($list, $position); |
591 | + } |
|
579 | 592 | return ($position >= $size) |
580 | 593 | ? array_merge($list, $items) |
581 | 594 | : array_merge(array_slice($list, 0, $position), $items, array_slice($list, $position)); |
@@ -659,8 +672,9 @@ discard block |
||
659 | 672 | static $take = false; |
660 | 673 | $take = $take ?: curry(function($count, $list) { |
661 | 674 | $length = length($list); |
662 | - if ($count > $length || $count < -$length) |
|
663 | - return $list; |
|
675 | + if ($count > $length || $count < -$length) { |
|
676 | + return $list; |
|
677 | + } |
|
664 | 678 | if(is_string($list)) { |
665 | 679 | return ($count >= 0) |
666 | 680 | ? substr($list, 0, $count) |
@@ -694,8 +708,9 @@ discard block |
||
694 | 708 | $takeWhile = $takeWhile ?: curry(function($predicate, $list) { |
695 | 709 | $index = 0; |
696 | 710 | $size = length($list); |
697 | - while ($index < $size && $predicate($list[$index])) |
|
698 | - $index ++; |
|
711 | + while ($index < $size && $predicate($list[$index])) { |
|
712 | + $index ++; |
|
713 | + } |
|
699 | 714 | return array_slice($list, 0, $index); |
700 | 715 | }); |
701 | 716 | return _apply($takeWhile, func_get_args()); |
@@ -720,8 +735,9 @@ discard block |
||
720 | 735 | static $takeLastWhile = false; |
721 | 736 | $takeLastWhile = $takeLastWhile ?: curry(function($predicate, $list) { |
722 | 737 | $index = length($list) - 1; |
723 | - while ($index >= 0 && $predicate($list[$index])) |
|
724 | - $index --; |
|
738 | + while ($index >= 0 && $predicate($list[$index])) { |
|
739 | + $index --; |
|
740 | + } |
|
725 | 741 | return array_slice($list, $index + 1); |
726 | 742 | }); |
727 | 743 | return _apply($takeLastWhile, func_get_args()); |
@@ -748,8 +764,9 @@ discard block |
||
748 | 764 | $takeUntil = $takeUntil ?: curry(function($predicate, $list) { |
749 | 765 | $index = 0; |
750 | 766 | $size = length($list); |
751 | - while ($index < $size && !$predicate($list[$index])) |
|
752 | - $index ++; |
|
767 | + while ($index < $size && !$predicate($list[$index])) { |
|
768 | + $index ++; |
|
769 | + } |
|
753 | 770 | return array_slice($list, 0, $index); |
754 | 771 | }); |
755 | 772 | return _apply($takeUntil, func_get_args()); |
@@ -774,8 +791,9 @@ discard block |
||
774 | 791 | static $takeLastUntil = false; |
775 | 792 | $takeLastUntil = $takeLastUntil ?: curry(function($predicate, $list) { |
776 | 793 | $index = length($list) - 1; |
777 | - while ($index >= 0 && !$predicate($list[$index])) |
|
778 | - $index --; |
|
794 | + while ($index >= 0 && !$predicate($list[$index])) { |
|
795 | + $index --; |
|
796 | + } |
|
779 | 797 | return array_slice($list, $index + 1); |
780 | 798 | }); |
781 | 799 | return _apply($takeLastUntil, func_get_args()); |
@@ -807,8 +825,9 @@ discard block |
||
807 | 825 | $remove = $remove ?: curry(function($count, $list) { |
808 | 826 | // ... |
809 | 827 | $length = length($list); |
810 | - if ($count > $length || $count < -$length) |
|
811 | - return []; |
|
828 | + if ($count > $length || $count < -$length) { |
|
829 | + return []; |
|
830 | + } |
|
812 | 831 | $count = ($count > 0) |
813 | 832 | ? $count - $length |
814 | 833 | : $count + $length; |
@@ -845,8 +864,9 @@ discard block |
||
845 | 864 | $removeWhile = $removeWhile ?: curry(function($predicate, $list) { |
846 | 865 | $index = 0; |
847 | 866 | $size = length($list); |
848 | - while ($index < $size && $predicate($list[$index])) |
|
849 | - $index ++; |
|
867 | + while ($index < $size && $predicate($list[$index])) { |
|
868 | + $index ++; |
|
869 | + } |
|
850 | 870 | return array_slice($list, $index); |
851 | 871 | }); |
852 | 872 | return _apply($removeWhile, func_get_args()); |
@@ -871,8 +891,9 @@ discard block |
||
871 | 891 | static $removeLastWhile = false; |
872 | 892 | $removeLastWhile = $removeLastWhile ?: curry(function($predicate, $list) { |
873 | 893 | $index = length($list) - 1; |
874 | - while ($index >= 0 && $predicate($list[$index])) |
|
875 | - $index --; |
|
894 | + while ($index >= 0 && $predicate($list[$index])) { |
|
895 | + $index --; |
|
896 | + } |
|
876 | 897 | return array_slice($list, 0, $index + 1); |
877 | 898 | }); |
878 | 899 | return _apply($removeLastWhile, func_get_args()); |
@@ -900,8 +921,9 @@ discard block |
||
900 | 921 | $removeUntil = $removeUntil ?: curry(function($predicate, $list) { |
901 | 922 | $index = 0; |
902 | 923 | $size = length($list); |
903 | - while ($index < $size && !$predicate($list[$index])) |
|
904 | - $index ++; |
|
924 | + while ($index < $size && !$predicate($list[$index])) { |
|
925 | + $index ++; |
|
926 | + } |
|
905 | 927 | return array_slice($list, $index); |
906 | 928 | }); |
907 | 929 | return _apply($removeUntil, func_get_args()); |
@@ -927,8 +949,9 @@ discard block |
||
927 | 949 | static $removeLastUntil = false; |
928 | 950 | $removeLastUntil = $removeLastUntil ?: curry(function($predicate, $list) { |
929 | 951 | $index = length($list) - 1; |
930 | - while ($index >= 0 && !$predicate($list[$index])) |
|
931 | - $index --; |
|
952 | + while ($index >= 0 && !$predicate($list[$index])) { |
|
953 | + $index --; |
|
954 | + } |
|
932 | 955 | return array_slice($list, 0, $index + 1); |
933 | 956 | }); |
934 | 957 | return _apply($removeLastUntil, func_get_args()); |
@@ -981,8 +1004,9 @@ discard block |
||
981 | 1004 | static $slices = false; |
982 | 1005 | $slices = $slices ?: curry(function($size, &$list) { |
983 | 1006 | $length = length($list); |
984 | - if ($length == 0) |
|
985 | - return is_string($list) ? [''] : []; |
|
1007 | + if ($length == 0) { |
|
1008 | + return is_string($list) ? [''] : []; |
|
1009 | + } |
|
986 | 1010 | $start = 0; |
987 | 1011 | $result = []; |
988 | 1012 | $slicer = is_string($list) ? 'substr' : 'array_slice'; |
@@ -1043,8 +1067,9 @@ discard block |
||
1043 | 1067 | static $findIndex = false; |
1044 | 1068 | $findIndex = $findIndex ?: curry(function($predicate, $list) { |
1045 | 1069 | foreach ($list as $key => &$value) { |
1046 | - if ($predicate($value)) |
|
1047 | - return $key; |
|
1070 | + if ($predicate($value)) { |
|
1071 | + return $key; |
|
1072 | + } |
|
1048 | 1073 | } |
1049 | 1074 | return null; |
1050 | 1075 | }); |
@@ -1074,8 +1099,9 @@ discard block |
||
1074 | 1099 | $keys = array_keys($list); |
1075 | 1100 | $index = count($keys) - 1; |
1076 | 1101 | while ($index >= 0) { |
1077 | - if ($predicate($list[$keys[$index]])) |
|
1078 | - return $keys[$index]; |
|
1102 | + if ($predicate($list[$keys[$index]])) { |
|
1103 | + return $keys[$index]; |
|
1104 | + } |
|
1079 | 1105 | $index --; |
1080 | 1106 | } |
1081 | 1107 | return null; |
@@ -1102,8 +1128,9 @@ discard block |
||
1102 | 1128 | static $find = false; |
1103 | 1129 | $find = $find ?: curry(function($predicate, $list) { |
1104 | 1130 | foreach ($list as $key => &$value) { |
1105 | - if ($predicate($value)) |
|
1106 | - return $value; |
|
1131 | + if ($predicate($value)) { |
|
1132 | + return $value; |
|
1133 | + } |
|
1107 | 1134 | } |
1108 | 1135 | return null; |
1109 | 1136 | }); |
@@ -1131,8 +1158,9 @@ discard block |
||
1131 | 1158 | $keys = array_keys($list); |
1132 | 1159 | $index = count($keys) - 1; |
1133 | 1160 | while ($index >= 0) { |
1134 | - if ($predicate($list[$keys[$index]])) |
|
1135 | - return $list[$keys[$index]]; |
|
1161 | + if ($predicate($list[$keys[$index]])) { |
|
1162 | + return $list[$keys[$index]]; |
|
1163 | + } |
|
1136 | 1164 | $index --; |
1137 | 1165 | } |
1138 | 1166 | return null; |
@@ -1176,8 +1204,9 @@ discard block |
||
1176 | 1204 | $keys = array_keys($list); |
1177 | 1205 | $length = count($keys); |
1178 | 1206 | while ($index < $length) { |
1179 | - if (_equals($item, $list[$keys[$index]])) |
|
1180 | - return $keys[$index]; |
|
1207 | + if (_equals($item, $list[$keys[$index]])) { |
|
1208 | + return $keys[$index]; |
|
1209 | + } |
|
1181 | 1210 | $index ++; |
1182 | 1211 | } |
1183 | 1212 | return -1; |
@@ -1215,8 +1244,9 @@ discard block |
||
1215 | 1244 | $keys = array_keys($list); |
1216 | 1245 | $index = count($list) - 1; |
1217 | 1246 | while ($index >= 0) { |
1218 | - if (_equals($list[$keys[$index]], $item)) |
|
1219 | - return $keys[$index]; |
|
1247 | + if (_equals($list[$keys[$index]], $item)) { |
|
1248 | + return $keys[$index]; |
|
1249 | + } |
|
1220 | 1250 | $index --; |
1221 | 1251 | } |
1222 | 1252 | return -1; |
@@ -1316,8 +1346,9 @@ discard block |
||
1316 | 1346 | $result = []; |
1317 | 1347 | foreach($list as $item) { |
1318 | 1348 | $index = $fn($item); |
1319 | - if (! isset($result[$index])) |
|
1320 | - $result[$index] = []; |
|
1349 | + if (! isset($result[$index])) { |
|
1350 | + $result[$index] = []; |
|
1351 | + } |
|
1321 | 1352 | $result[$index][] = $item; |
1322 | 1353 | } |
1323 | 1354 | return $result; |
@@ -1346,8 +1377,9 @@ discard block |
||
1346 | 1377 | $pairsFrom = $pairsFrom ?: curry(function($list1, $list2) { |
1347 | 1378 | $length1 = count($list1); |
1348 | 1379 | $length2 = count($list2); |
1349 | - if (0 == $length1 || 0 == $length2) |
|
1350 | - return []; |
|
1380 | + if (0 == $length1 || 0 == $length2) { |
|
1381 | + return []; |
|
1382 | + } |
|
1351 | 1383 | $result = []; |
1352 | 1384 | $index = 0; |
1353 | 1385 | $length = min($length1, $length2); |
@@ -15,8 +15,6 @@ discard block |
||
15 | 15 | * @stream |
16 | 16 | * @signature (a -> b) -> [a] -> [b] |
17 | 17 | * @signature (a -> b) -> {k: a} -> {k: b} |
18 | - * @param callable $fn |
|
19 | - * @param array $list |
|
20 | 18 | * @return array |
21 | 19 | */ |
22 | 20 | function map() { |
@@ -36,8 +34,6 @@ discard block |
||
36 | 34 | * |
37 | 35 | * @stream |
38 | 36 | * @signature (a -> [b]) -> [a] -> [b] |
39 | - * @param callable $fn |
|
40 | - * @param array $list |
|
41 | 37 | * @return array |
42 | 38 | */ |
43 | 39 | function chain() { |
@@ -66,8 +62,6 @@ discard block |
||
66 | 62 | * ``` |
67 | 63 | * @stream |
68 | 64 | * @signature (a -> Boolean) -> [a] -> [a] |
69 | - * @param callable $fn |
|
70 | - * @param array|\ArrayObject|\SplObjectStorage $list |
|
71 | 65 | * @return array|\ArrayObject|\SplObjectStorage|callable |
72 | 66 | */ |
73 | 67 | function filter() { |
@@ -150,8 +144,6 @@ discard block |
||
150 | 144 | * ``` |
151 | 145 | * |
152 | 146 | * @signature (a -> Boolean) -> {k: a} -> {k: a} |
153 | - * @param callable $predicate |
|
154 | - * @param array|\ArrayObject|\SplObjectStorage $list |
|
155 | 147 | * @return array|\ArrayObject|\SplObjectStorage|callable |
156 | 148 | */ |
157 | 149 | function filter_values() { |
@@ -195,9 +187,6 @@ discard block |
||
195 | 187 | * |
196 | 188 | * @stream |
197 | 189 | * @signature (* -> a -> *) -> * -> [a] -> * |
198 | - * @param callable $fn |
|
199 | - * @param mixed $initial |
|
200 | - * @param array $list |
|
201 | 190 | * @return array |
202 | 191 | */ |
203 | 192 | function reduce() { |
@@ -223,8 +212,6 @@ discard block |
||
223 | 212 | * |
224 | 213 | * @stream |
225 | 214 | * @signature (a -> *) -> [a] -> [a] |
226 | - * @param callable $fn |
|
227 | - * @param array $list |
|
228 | 215 | * @return array |
229 | 216 | */ |
230 | 217 | function each() { |
@@ -251,7 +238,6 @@ discard block |
||
251 | 238 | * @stream |
252 | 239 | * @signature [a] -> a |
253 | 240 | * @signature String -> String |
254 | - * @param array|string $list |
|
255 | 241 | * @return mixed |
256 | 242 | */ |
257 | 243 | function head() { |
@@ -276,7 +262,6 @@ discard block |
||
276 | 262 | * @stream |
277 | 263 | * @signature [a] -> a |
278 | 264 | * @signature String -> String |
279 | - * @param array|string $list |
|
280 | 265 | * @return mixed |
281 | 266 | */ |
282 | 267 | function last () { |
@@ -306,7 +291,6 @@ discard block |
||
306 | 291 | * @stream |
307 | 292 | * @signature [a] -> a |
308 | 293 | * @signature String -> String |
309 | - * @param array|string $list |
|
310 | 294 | * @return array |
311 | 295 | */ |
312 | 296 | function init () { |
@@ -340,7 +324,6 @@ discard block |
||
340 | 324 | * @stream |
341 | 325 | * @signature [a] -> a |
342 | 326 | * @signature String -> String |
343 | - * @param array|string $list |
|
344 | 327 | * @return array |
345 | 328 | */ |
346 | 329 | function tail () { |
@@ -368,7 +351,6 @@ discard block |
||
368 | 351 | * @stream |
369 | 352 | * @signature [a] -> [a] |
370 | 353 | * @signature String -> String |
371 | - * @param array|string $list |
|
372 | 354 | * @return array |
373 | 355 | */ |
374 | 356 | function reverse () { |
@@ -392,7 +374,6 @@ discard block |
||
392 | 374 | * @stream |
393 | 375 | * @signature [a] -> Number |
394 | 376 | * @signature String -> Number |
395 | - * @param array|string $list |
|
396 | 377 | * @return int |
397 | 378 | */ |
398 | 379 | function length() { |
@@ -416,8 +397,6 @@ discard block |
||
416 | 397 | * |
417 | 398 | * @stream |
418 | 399 | * @signature (a -> Boolean) -> [a] -> Boolean |
419 | - * @param callable $predicate |
|
420 | - * @param array $list |
|
421 | 400 | * @return bool |
422 | 401 | */ |
423 | 402 | function allSatisfies() { |
@@ -443,8 +422,6 @@ discard block |
||
443 | 422 | * |
444 | 423 | * @stream |
445 | 424 | * @signature (a -> Boolean) -> [a] -> Boolean |
446 | - * @param callable $predicate |
|
447 | - * @param array $list |
|
448 | 425 | * @return bool |
449 | 426 | */ |
450 | 427 | function anySatisfies() { |
@@ -470,8 +447,6 @@ discard block |
||
470 | 447 | * @stream |
471 | 448 | * @signature [*] -> [*] -> [*] |
472 | 449 | * @signature String -> String -> String |
473 | - * @param array $list1 |
|
474 | - * @param array $list2 |
|
475 | 450 | * @return array |
476 | 451 | */ |
477 | 452 | function concat() { |
@@ -494,7 +469,6 @@ discard block |
||
494 | 469 | * |
495 | 470 | * @stream |
496 | 471 | * @signature [[a]] -> [a] |
497 | - * @param array $lists |
|
498 | 472 | * @return array |
499 | 473 | */ |
500 | 474 | function concatAll() { |
@@ -529,9 +503,6 @@ discard block |
||
529 | 503 | * @stream |
530 | 504 | * @signature Number -> a -> [a] -> [a] |
531 | 505 | * @signature Number -> String -> String -> String |
532 | - * @param int $position |
|
533 | - * @param mixed $item |
|
534 | - * @param array $list |
|
535 | 506 | * @return array |
536 | 507 | */ |
537 | 508 | function insert() { |
@@ -559,9 +530,6 @@ discard block |
||
559 | 530 | * @stream |
560 | 531 | * @signature Number -> [a] -> [a] -> [a] |
561 | 532 | * @signature Number -> String -> String -> String |
562 | - * @param int $position |
|
563 | - * @param mixed $items |
|
564 | - * @param array $list |
|
565 | 533 | * @return array |
566 | 534 | */ |
567 | 535 | function insertAll() { |
@@ -594,8 +562,6 @@ discard block |
||
594 | 562 | * @stream |
595 | 563 | * @signature * -> [*] -> [*] |
596 | 564 | * @signature String -> String -> String |
597 | - * @param mixed $item |
|
598 | - * @param array $list |
|
599 | 565 | * @return array |
600 | 566 | */ |
601 | 567 | function append() { |
@@ -620,8 +586,6 @@ discard block |
||
620 | 586 | * @stream |
621 | 587 | * @signature a -> [a] -> [a] |
622 | 588 | * @signature String -> String -> String |
623 | - * @param mixed $item |
|
624 | - * @param array $list |
|
625 | 589 | * @return array |
626 | 590 | */ |
627 | 591 | function prepend() { |
@@ -651,8 +615,6 @@ discard block |
||
651 | 615 | * @stream |
652 | 616 | * @signature Number -> [a] -> [a] |
653 | 617 | * @signature Number -> String -> String |
654 | - * @param int $count |
|
655 | - * @param array $list |
|
656 | 618 | * @return array |
657 | 619 | */ |
658 | 620 | function take() { |
@@ -685,8 +647,6 @@ discard block |
||
685 | 647 | * |
686 | 648 | * @stream |
687 | 649 | * @signature (a -> Boolean) -> [a] -> [a] |
688 | - * @param callable $predicate |
|
689 | - * @param array $list |
|
690 | 650 | * @return array |
691 | 651 | */ |
692 | 652 | function takeWhile() { |
@@ -712,8 +672,6 @@ discard block |
||
712 | 672 | * |
713 | 673 | * @stream |
714 | 674 | * @signature (a -> Boolean) -> [a] -> [a] |
715 | - * @param callable $predicate |
|
716 | - * @param array $list |
|
717 | 675 | * @return array |
718 | 676 | */ |
719 | 677 | function takeLastWhile() { |
@@ -739,8 +697,6 @@ discard block |
||
739 | 697 | * |
740 | 698 | * @stream |
741 | 699 | * @signature (a -> Boolean) -> [a] -> [a] |
742 | - * @param callable $predicate |
|
743 | - * @param array $list |
|
744 | 700 | * @return array |
745 | 701 | */ |
746 | 702 | function takeUntil() { |
@@ -766,8 +722,6 @@ discard block |
||
766 | 722 | * |
767 | 723 | * @stream |
768 | 724 | * @signature (a -> Boolean) -> [a] -> [a] |
769 | - * @param callable $predicate |
|
770 | - * @param array $list |
|
771 | 725 | * @return array |
772 | 726 | */ |
773 | 727 | function takeLastUntil() { |
@@ -798,8 +752,6 @@ discard block |
||
798 | 752 | * @stream |
799 | 753 | * @signature Number -> [a] -> [a] |
800 | 754 | * @signature Number -> String -> String |
801 | - * @param int $count |
|
802 | - * @param array $list |
|
803 | 755 | * @return array |
804 | 756 | */ |
805 | 757 | function remove() { |
@@ -836,8 +788,6 @@ discard block |
||
836 | 788 | * |
837 | 789 | * @stream |
838 | 790 | * @signature (a -> Boolean) -> [a] -> [a] |
839 | - * @param callable $predicate |
|
840 | - * @param array $list |
|
841 | 791 | * @return array |
842 | 792 | */ |
843 | 793 | function removeWhile() { |
@@ -863,8 +813,6 @@ discard block |
||
863 | 813 | * |
864 | 814 | * @stream |
865 | 815 | * @signature (a -> Boolean) -> [a] -> [a] |
866 | - * @param callable $predicate |
|
867 | - * @param array $list |
|
868 | 816 | * @return array |
869 | 817 | */ |
870 | 818 | function removeLastWhile() { |
@@ -891,8 +839,6 @@ discard block |
||
891 | 839 | * |
892 | 840 | * @stream |
893 | 841 | * @signature (a -> Boolean) -> [a] -> [a] |
894 | - * @param callable $predicate |
|
895 | - * @param array $list |
|
896 | 842 | * @return array |
897 | 843 | */ |
898 | 844 | function removeUntil() { |
@@ -919,8 +865,6 @@ discard block |
||
919 | 865 | * |
920 | 866 | * @stream |
921 | 867 | * @signature (a -> Boolean) -> [a] -> [a] |
922 | - * @param callable $predicate |
|
923 | - * @param array $list |
|
924 | 868 | * @return array |
925 | 869 | */ |
926 | 870 | function removeLastUntil() { |
@@ -943,7 +887,6 @@ discard block |
||
943 | 887 | * |
944 | 888 | * @stream |
945 | 889 | * @signature [(k, v)] -> {k: v} |
946 | - * @param array $pairs |
|
947 | 890 | * @return stdClass |
948 | 891 | */ |
949 | 892 | function fromPairs() { |
@@ -973,8 +916,6 @@ discard block |
||
973 | 916 | * @stream |
974 | 917 | * @signature Number -> [a] -> [[a]] |
975 | 918 | * @signature Number -> String -> [String] |
976 | - * @param int $size |
|
977 | - * @param array $list |
|
978 | 919 | * @return array |
979 | 920 | */ |
980 | 921 | function slices() { |
@@ -1008,8 +949,6 @@ discard block |
||
1008 | 949 | * @stream |
1009 | 950 | * @signature a -> [a] -> Boolean |
1010 | 951 | * @signature String -> String -> Boolean |
1011 | - * @param mixed $item |
|
1012 | - * @param array|string $list |
|
1013 | 952 | * @return bool |
1014 | 953 | */ |
1015 | 954 | function contains() { |
@@ -1035,8 +974,6 @@ discard block |
||
1035 | 974 | * @stream |
1036 | 975 | * @signature (a -> Boolean) -> [a] -> Maybe(Number) |
1037 | 976 | * @signature (v -> Boolean) -> {k: v} -> Maybe(k) |
1038 | - * @param callable $predicate |
|
1039 | - * @param array $list |
|
1040 | 977 | * @return mixed |
1041 | 978 | */ |
1042 | 979 | function findIndex() { |
@@ -1064,8 +1001,6 @@ discard block |
||
1064 | 1001 | * @stream |
1065 | 1002 | * @signature (a -> Boolean) -> [a] -> Maybe(Number) |
1066 | 1003 | * @signature (v -> Boolean) -> {k: v} -> Maybe(k) |
1067 | - * @param callable $predicate |
|
1068 | - * @param array $list |
|
1069 | 1004 | * @return mixed |
1070 | 1005 | */ |
1071 | 1006 | function findLastIndex() { |
@@ -1094,8 +1029,6 @@ discard block |
||
1094 | 1029 | * |
1095 | 1030 | * @stream |
1096 | 1031 | * @signature (a -> Boolean) -> [a] -> Maybe(a) |
1097 | - * @param callable $predicate |
|
1098 | - * @param array $list |
|
1099 | 1032 | * @return mixed |
1100 | 1033 | */ |
1101 | 1034 | function find() { |
@@ -1121,8 +1054,6 @@ discard block |
||
1121 | 1054 | * |
1122 | 1055 | * @stream |
1123 | 1056 | * @signature (a -> Boolean) -> [a] -> Maybe(a) |
1124 | - * @param callable $predicate |
|
1125 | - * @param array $list |
|
1126 | 1057 | * @return mixed |
1127 | 1058 | */ |
1128 | 1059 | function findLast() { |
@@ -1160,8 +1091,6 @@ discard block |
||
1160 | 1091 | * @signature a -> [a] -> Number |
1161 | 1092 | * @signature v -> {k: v} -> Maybe(k) |
1162 | 1093 | * @signature String -> String -> Number |
1163 | - * @param mixed $item |
|
1164 | - * @param array $list |
|
1165 | 1094 | * @return int |
1166 | 1095 | */ |
1167 | 1096 | function indexOf() { |
@@ -1200,8 +1129,6 @@ discard block |
||
1200 | 1129 | * @signature a -> [a] -> Number |
1201 | 1130 | * @signature v -> {k: v} -> Maybe(k) |
1202 | 1131 | * @signature String -> String -> Number |
1203 | - * @param mixed $item |
|
1204 | - * @param array $list |
|
1205 | 1132 | * @return int |
1206 | 1133 | */ |
1207 | 1134 | function lastIndexOf() { |
@@ -1235,8 +1162,6 @@ discard block |
||
1235 | 1162 | * |
1236 | 1163 | * @stream |
1237 | 1164 | * @signature (a -> a -> Boolean) -> [a] -> [a] |
1238 | - * @param callable $areEqual |
|
1239 | - * @param array $list |
|
1240 | 1165 | * @return array |
1241 | 1166 | */ |
1242 | 1167 | function uniqueBy() { |
@@ -1273,7 +1198,6 @@ discard block |
||
1273 | 1198 | * |
1274 | 1199 | * @stream |
1275 | 1200 | * @signature [a] -> [a] |
1276 | - * @param array $list |
|
1277 | 1201 | * @return array |
1278 | 1202 | */ |
1279 | 1203 | function unique() { |
@@ -1306,8 +1230,6 @@ discard block |
||
1306 | 1230 | * |
1307 | 1231 | * @stream |
1308 | 1232 | * @signature (a -> String) -> [a] -> {String: a} |
1309 | - * @param callable $fn |
|
1310 | - * @param array $list |
|
1311 | 1233 | * @return array |
1312 | 1234 | */ |
1313 | 1235 | function groupBy() { |
@@ -1337,8 +1259,6 @@ discard block |
||
1337 | 1259 | * |
1338 | 1260 | * @stream |
1339 | 1261 | * @signature [a] -> [b] -> [[a,b]] |
1340 | - * @param array $list1 |
|
1341 | - * @param array $list2 |
|
1342 | 1262 | * @return array |
1343 | 1263 | */ |
1344 | 1264 | function pairsFrom() { |
@@ -1383,8 +1303,6 @@ discard block |
||
1383 | 1303 | * |
1384 | 1304 | * @stream |
1385 | 1305 | * @signature (a -> a -> Boolean) -> [a] -> [a] |
1386 | - * @param callable $compare |
|
1387 | - * @param array $list |
|
1388 | 1306 | * @return array |
1389 | 1307 | */ |
1390 | 1308 | function sort() { |