Arrays\filterAll()

higher-order predicate short-circuit accepts iterable returns Closure returns bool pure
(T → bool) → (Iterable → bool)
At a glance — Bind a predicate; the returned Closure asks "do all elements match?". Stops at the first failure — safe with infinite Generators (if a mismatch exists).

Creates a Closure that returns true when every element of an array or iterable passes the predicate. Short-circuits on the first non-matching value.

/**
  * @param callable(mixed):bool $function
  * @return Closure(iterable<int|string, mixed>):bool
  */
Arrays\filterAll(callable $function): Closure

Returned Closure

When Arrays\filterAll() is called, it returns the following Closure which can be used like a regular function.

/**
  * @param iterable<int|string, mixed> $source
  * @return bool
  */
$function (iterable $source): bool

Examples

Partial Application

This can be used to create a simple closure which can be used as a regular function.

$allPositive = Arrays\filterAll(fn($v) => $v > 0);

var_dump($allPositive([1, 2, 3]));    // true
var_dump($allPositive([1, -2, 3]));   // false

Curried

This can be called inline using currying.

var_dump(Arrays\filterAll('is_int')([1, 2, 'three'])); // false

Details

Arrays Functions

Releated Array filter Functions