| @@ 11-18 (lines=8) @@ | ||
| 8 | ||
| 9 | use Closure; |
|
| 10 | ||
| 11 | function all(callable $pred): Closure |
|
| 12 | { |
|
| 13 | return function (array $xs) use ($pred): bool { |
|
| 14 | return array_reduce($xs, function (bool $prev, $x) use ($pred): bool { |
|
| 15 | return $prev && $pred($x); |
|
| 16 | }, true); |
|
| 17 | }; |
|
| 18 | } |
|
| 19 | ||
| @@ 11-18 (lines=8) @@ | ||
| 8 | ||
| 9 | use Closure; |
|
| 10 | ||
| 11 | function any(callable $pred): Closure |
|
| 12 | { |
|
| 13 | return function (array $xs) use ($pred): bool { |
|
| 14 | return array_reduce($xs, function (bool $prev, $x) use ($pred): bool { |
|
| 15 | return $prev ?: $pred($x); |
|
| 16 | }, false); |
|
| 17 | }; |
|
| 18 | } |
|
| 19 | ||