@@ 320-330 (lines=11) @@ | ||
317 | * @param array $list |
|
318 | * @return bool |
|
319 | */ |
|
320 | function allSatisfies() { |
|
321 | static $allSatisfies = false; |
|
322 | $allSatisfies = $allSatisfies ?: curry(function($predicate, $list) { |
|
323 | foreach ($list as $item) { |
|
324 | if (! $predicate($item)) |
|
325 | return false; |
|
326 | } |
|
327 | return true; |
|
328 | }); |
|
329 | return _apply($allSatisfies, func_get_args()); |
|
330 | } |
|
331 | ||
332 | /** |
|
333 | * Checks if the `$predicate` is verified by **any** item of the array. |
|
@@ 347-357 (lines=11) @@ | ||
344 | * @param array $list |
|
345 | * @return bool |
|
346 | */ |
|
347 | function anySatisfies() { |
|
348 | static $anySatisfies = false; |
|
349 | $anySatisfies = $anySatisfies ?: curry(function($predicate, $list) { |
|
350 | foreach ($list as $item) { |
|
351 | if ($predicate($item)) |
|
352 | return true; |
|
353 | } |
|
354 | return false; |
|
355 | }); |
|
356 | return _apply($anySatisfies, func_get_args()); |
|
357 | } |
|
358 | ||
359 | /** |
|
360 | * Concatenates two arrays or strings. |
|
@@ 939-949 (lines=11) @@ | ||
936 | * @param array $list |
|
937 | * @return mixed |
|
938 | */ |
|
939 | function findIndex() { |
|
940 | static $findIndex = false; |
|
941 | $findIndex = $findIndex ?: curry(function($predicate, $list) { |
|
942 | foreach ($list as $key => &$value) { |
|
943 | if ($predicate($value)) |
|
944 | return $key; |
|
945 | } |
|
946 | return null; |
|
947 | }); |
|
948 | return _apply($findIndex, func_get_args()); |
|
949 | } |
|
950 | ||
951 | /** |
|
952 | * Returns the position/key of the last item satisfying the |
|
@@ 998-1008 (lines=11) @@ | ||
995 | * @param array $list |
|
996 | * @return mixed |
|
997 | */ |
|
998 | function find() { |
|
999 | static $find = false; |
|
1000 | $find = $find ?: curry(function($predicate, $list) { |
|
1001 | foreach ($list as $key => &$value) { |
|
1002 | if ($predicate($value)) |
|
1003 | return $value; |
|
1004 | } |
|
1005 | return null; |
|
1006 | }); |
|
1007 | return _apply($find, func_get_args()); |
|
1008 | } |
|
1009 | ||
1010 | /** |
|
1011 | * Returns the last item satisfying the predicate in |
@@ 369-379 (lines=11) @@ | ||
366 | * @param mixed $object |
|
367 | * @return bool |
|
368 | */ |
|
369 | function satisfiesAll() { |
|
370 | static $satisfiesAll = false; |
|
371 | $satisfiesAll = $satisfiesAll ?: curry(function($predicates, $object) { |
|
372 | foreach ($predicates as $key => $predicate) { |
|
373 | if (!satisfies($predicate, $key, $object)) |
|
374 | return false; |
|
375 | } |
|
376 | return true; |
|
377 | }); |
|
378 | return _apply($satisfiesAll, func_get_args()); |
|
379 | } |
|
380 | ||
381 | /** |
|
382 | * Checks if a list of attribute/value of an object/array passes any of the given predicates. |
|
@@ 407-417 (lines=11) @@ | ||
404 | * @param mixed $object |
|
405 | * @return bool |
|
406 | */ |
|
407 | function satisfiesAny() { |
|
408 | static $satisfiesAny = false; |
|
409 | $satisfiesAny = $satisfiesAny ?: curry(function($predicates, $object) { |
|
410 | foreach ($predicates as $key => $predicate) { |
|
411 | if (satisfies($predicate, $key, $object)) |
|
412 | return true; |
|
413 | } |
|
414 | return false; |
|
415 | }); |
|
416 | return _apply($satisfiesAny, func_get_args()); |
|
417 | } |
|
418 | ||
419 | /** |
|
420 | * Converts an object or associative array to an array of [key, value] pairs. |