On Fri, 17 Mar 2023 at 09:52, Robert Landers <landers.rob...@gmail.com>
wrote:

>
> I think this is already supported-ish. For example, here's a partial
> application in user space that seems to follow all the rules. Or at
> least the rules that are followed make sense.
>
> function partial(Closure $callable, ...$args): Closure {
>    return static fn(...$fullArgs) => $callable(...[...$args,
> ...$fullArgs]);
> }
>


The big difference between this and a native implementation is that the
closure doesn't have any information in its type signature. As well as
leading to less helpful error messages (type errors will be reported as
happening _inside_ the closure, rather than on the line that calls it),
this makes the parameters invisible to Reflection.

There's also no way to make it an instance method from userland, making
everything a bit verbose - Michał's example would become something like:

$size = Closure::apply(
     Closure::pipe(
          Closure::partial(amap(...), chr(...)),
          Closure::partial( implode (...), ','),
          amap(...)
     ),
    $arr
);

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to