Re: First-class callable partial application
| From: | Rowan Tommins | Date: | Thu, 16 Mar 2023 09:14:38 +0000 |
| Subject: | Re: First-class callable partial application | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119718@lists.php.net to get a copy of this message | ||
On 15/03/2023 21:12, Dan Ackroyd wrote:
Would it be desirable to split those two things into two separate RFCs, by having the first RFC not have native syntax support, but instead another static method on Closure? e.g. something like: Closure::partial($callable, array $position_params, array $named_params): Closure {}Hm... now we have the first-class callable syntax, making it an instance method on Closure would allow this: $mapFoo = array_map(...)->partial([$foo]); $filterFoo = array_filter(...)->partial([1 => $foo]); Which could copy over the full signature, so be equivalent to this: $mapFoo = static fn(array ...$arrays): array => array_map($foo, ...$arrays); $filterFoo = static fn(array $array, int $mode = 0): array => array_filter($array, $foo, $mode); While being a similar length to a much less rich version: $mapFoo = fn($array) => array_map($foo, $array); $filterFoo = fn($array) => array_filter($array, $foo); Regards, -- Rowan Tommins [IMSoP]