@@ 43-53 (lines=11) @@ | ||
40 | * @param array $list |
|
41 | * @return array |
|
42 | */ |
|
43 | function chain() { |
|
44 | static $chain = false; |
|
45 | $chain = $chain ?: curry(function($fn, $list) { |
|
46 | $result = []; |
|
47 | foreach ($list as $item) { |
|
48 | $result = array_merge($result, $fn($item)); |
|
49 | } |
|
50 | return $result; |
|
51 | }); |
|
52 | return _apply($chain, func_get_args()); |
|
53 | } |
|
54 | ||
55 | /** |
|
56 | * Curried version of `array_filter` with modified order of arguments. |
|
@@ 70-81 (lines=12) @@ | ||
67 | * @param array $list |
|
68 | * @return array |
|
69 | */ |
|
70 | function filter() { |
|
71 | static $filter = false; |
|
72 | $filter = $filter ?: curry(function($fn, $list) { |
|
73 | $result = []; |
|
74 | foreach ($list as $item) { |
|
75 | if ($fn($item)) |
|
76 | $result[] = $item; |
|
77 | } |
|
78 | return $result; |
|
79 | }); |
|
80 | return _apply($filter, func_get_args()); |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * Curried version of `array_reduce` with modified order of |
@@ 240-250 (lines=11) @@ | ||
237 | * @param mixed $object |
|
238 | * @return mixed |
|
239 | */ |
|
240 | function getPath() { |
|
241 | static $getPath = false; |
|
242 | $getPath = $getPath ?: curry(function($path, $object) { |
|
243 | $result = $object; |
|
244 | foreach ($path as &$attr) { |
|
245 | $result = get($attr, $result); |
|
246 | } |
|
247 | return $result; |
|
248 | }); |
|
249 | return _apply($getPath, func_get_args()); |
|
250 | } |
|
251 | ||
252 | /** |
|
253 | * Returns a new array or object with the value of a key or a public attribute set |