Re: First-class callable partial application

From: Date: Thu, 16 Mar 2023 10:44:56 +0000
Subject: Re: First-class callable partial application
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  Groups: php.internals 
Request: Send a blank email to internals+get-119721@lists.php.net to get a copy of this message
On Thu, Mar 16, 2023 at 10:14 AM Rowan Tommins <rowan.collins@gmail..com> wrote: > > 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] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Rowan, that is actually fairly beautiful. May not even need the second RFC...

« previous php.internals (#119721) next »