Arrays\filterAny()

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 "does any element match?". Stops at the first match — safe with infinite Generators (if a match exists).

Creates a Closure that returns true when at least one element of an array or iterable passes the predicate. Short-circuits on the first match.

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

Returned Closure

When Arrays\filterAny() 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.

$anyNegative = Arrays\filterAny(fn($v) => $v < 0);

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

Curried

This can be called inline using currying.

var_dump(Arrays\filterAny('is_string')([1, 2, 'three'])); // true

Details

Arrays Functions

Releated Array filter Functions