Arrays\filterOr()

higher-order transformer variadic lazy accepts iterable returns Closure pure
...(T → bool) → (Iterable → Iterable)
At a glance — OR-combines multiple predicates into a single filter. Lazy — Generator in, Generator out, keys preserved.

Create a function which filters an array using multiple predicates, all of which any return true.

/**
 * Returns a Closure for filtering the passed array using multiple predicates, all of which any return true.
 *
 * @param callable(mixed): bool ...$callable The predicate functions that determines if the value should be kept.
 * @return Closure(array<int|string, mixed>): array<int|string, mixed>
 */
Arrays\filterOr(callable ...$callback): Closure

Returned Closure

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

/**
  * @param array<int|string, mixed> $array
  * @return array<int|string, mixed>
  */
$function (array $data): array

Examples

Partial Application

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

// Create a function that will filter out any number which is a multiple of 3 or 5.
$filter = Arrays\filterOr(
 fn($v) => $v % 3 === 0,  
 fn($v) => $v % 5 === 0  
);  

// Called as a function.
var_dump($filter([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); // [3, 5, 6, 9, 10]

Curried

This can be called inline using currying.

// Filter an array for all even numbers.

var_dump(Arrays\filterOr('is_numeric', fn($v) => $v % 2 === 0)(['Apple', 2, 3, 4, False, 6])); 

// [2, 4, 6]

Details

Arrays Functions

Releated Array filter Functions