Like arrayCompiler() but guarded by a validator — values that fail the validator are silently dropped rather than appended.
/**
* @param callable(mixed):bool $validator Applied before each append.
* @param mixed[] $inital Initial array contents.
* @return Closure
*/
Arrays\arrayCompilerTyped(callable $validator, array $inital = []): ClosureThis can be used to create a simple closure which can be used as a regular function.
$compile = Arrays\arrayCompilerTyped('is_int');
$compile = $compile(1);
$compile = $compile('two'); // dropped — not int
$compile = $compile(3);
var_dump($compile()); // [1, 3]This can be called inline using currying.
var_dump(Arrays\arrayCompilerTyped('is_string')('a')(1)('b')()); // ['a', 'b']