Creates a Closure that yields elements of an array or iterable until the predicate returns true — stops exclusive (the triggering element is NOT included).
/**
* @param callable(mixed): bool $conditional
* @return Closure(iterable<int|string, mixed>):(array<int|string, mixed>|\Generator<int|string, mixed>)
*/
Arrays\takeUntil(callable $conditional): ClosureWhen Arrays\takeUntil() is called, it returns the following Closure which can be used like a regular function.
/**
* @param iterable<int|string, mixed> $source
* @return array<int|string, mixed>|\Generator<int|string, mixed>
*/
$function (iterable $source): array|\GeneratorThis can be used to create a simple closure which can be used as a regular function.
$untilNegative = Arrays\takeUntil(fn($n) => $n < 0);
print_r($untilNegative([1, 2, 3, -1, 4])); // [1, 2, 3]