PHP: rfc:partial_function_application_v2
DRANK

IntroductionPartial Function Application (PFA) refers to the process of calling a function with only some of its required parameters, delaying the rest to a later time. It is logically equivalent to the following:function f(int $a, int $b, int $c) {}   $partialF = fn(int $b) => f(1, $b, 3);However, using an arrow function is often cumbersome, as it requires manually replicating all the parameter information. That is unnecessary work both for the author and reader.That is especially relevant when dealing with callbacks or the new pipe operator. For example:$result = array_map(static fn(string $string): string => str_replace('hello', 'hi', $string), $arr);   $foo > static fn(array $arr) => array_map(static fn(string $string): string => str_replace('hello', 'hi', $string), $arr) ;While the examples above show “all the trimmings,” including technically optional syntax, it is usually recommended to include type information, and many static analysis tools will require it. Even without…

wiki.php.net
Related Topics: PHP
1 comments