| @@ 10-44 (lines=35) @@ | ||
| 7 | ||
| 8 | use Zicht\Itertools\conversions; |
|
| 9 | ||
| 10 | trait AllTrait |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * Returns true when all elements of this iterable are not empty, otherwise returns false |
|
| 14 | * |
|
| 15 | * When the optional $STRATEGY argument is given, this argument is used to obtain the |
|
| 16 | * value which is tested to be empty. |
|
| 17 | * |
|
| 18 | * > iterable([1, 'hello world', true])->all() |
|
| 19 | * true |
|
| 20 | * |
|
| 21 | * > iterable([1, null, 3])->all() |
|
| 22 | * false |
|
| 23 | * |
|
| 24 | * @param null|string|\Closure $strategy Optional, when not specified !empty will be used |
|
| 25 | * @return null|bool |
|
| 26 | */ |
|
| 27 | public function all($strategy = null) |
|
| 28 | { |
|
| 29 | if ($this instanceof \Iterator) { |
|
| 30 | $strategy = conversions\mixed_to_value_getter($strategy); |
|
| 31 | ||
| 32 | foreach ($this as $item) { |
|
| 33 | $tempVarPhp54 = call_user_func($strategy, $item); |
|
| 34 | if (empty($tempVarPhp54)) { |
|
| 35 | return false; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | return true; |
|
| 40 | } |
|
| 41 | ||
| 42 | return null; |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| @@ 10-44 (lines=35) @@ | ||
| 7 | ||
| 8 | use Zicht\Itertools\conversions; |
|
| 9 | ||
| 10 | trait AnyTrait |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * Returns true when one or more element of this iterable is not empty, otherwise returns false |
|
| 14 | * |
|
| 15 | * When the optional $STRATEGY argument is given, this argument is used to obtain the |
|
| 16 | * value which is tested to be empty. |
|
| 17 | * |
|
| 18 | * > iterable([0, '', false])->any() |
|
| 19 | * false |
|
| 20 | * |
|
| 21 | * > iterable([1, null, 3])->any() |
|
| 22 | * true |
|
| 23 | * |
|
| 24 | * @param null|string|\Closure $strategy Optional, when not specified !empty will be used |
|
| 25 | * @return null|bool |
|
| 26 | */ |
|
| 27 | public function any($strategy = null) |
|
| 28 | { |
|
| 29 | if ($this instanceof \Iterator) { |
|
| 30 | $strategy = conversions\mixed_to_value_getter($strategy); |
|
| 31 | ||
| 32 | foreach ($this as $item) { |
|
| 33 | $tempVarPhp54 = call_user_func($strategy, $item); |
|
| 34 | if (!empty($tempVarPhp54)) { |
|
| 35 | return true; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | return false; |
|
| 40 | } |
|
| 41 | ||
| 42 | return null; |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||