>
> > > > This makes me wonder: can we create a partial programmatically?
> Wouldn't
> > > > that be needed for some use cases?
> > > > Partial::createFromCallable($callable, the-args)?
> > > >
> > > > Nicolas
> > >
> > > I cannot think of a use case where that would be needed.  Since you can
> > > partial-ize any callable, including a dynamic one, if you needed to do
> > > something like partial-ize one of a series of function calls you can do
> > > that already:
> > >
> > > $c = match($some_input) {
> > >   'A' => 'func_a',
> > >   'B' => 'func_b',
> > >   'C' => 'func_c',
> > > };
> > >
> > > $p = $c(1, 2 ?, 4);
> > >
> > > Though at that point, just partialing them in the first place inside
> the
> > > match would be better as then you never have a function name in a
> string to
> > > begin with.
> > >
> >
> > Here is a use case: high-order argument resolvers / function reducers.
> >
> > What I mean is a function that takes a callable as arguments, resolves as
> > many args of the callable as it can using whatever logic fits, and
> returns
> > a callable with fewer arguments (only the non-resolved ones - aka a
> > Partial).
>
> You're thinking something like an auto-wiring routine for callables?
>
> function volume(int $x, int $y, int $z) { ... }
>
> class Resolver {
>   private array $context = ['x' => 5];
>
>   public resolve(callable $c) {
>     foreach (get_argument_names_from_param($c) as $k) {
>       if (isset($this->context[$k]) {
>         $args[$k] = $this->context[$k];
>       }
>     }
>     return $c(...$args, ?);
>   }
> }
>
> $r = new Resolver();
> $c2 = $r->resolve(volume(?));
>
> print $c2(y: 3, z: 9);
>
> I haven't tried running that (I don't feel like messing with the necessary
> reflection), but... I think it would work already?  Whether that's useful
> in practice or not I don't know. :-)
>

Oh, indeed, that's super great!

Then remains my question about replacing Partial by Closure. I think this
would be an important feature and that would remove the need for
ReflectionPartial.

About reflection, the following behaviors are quite problematic to me:
> ReflectionFunction(Closure::fromCallable($arbitrary_callable)) to
normalize all callables to a single reflection interface will no longer work

I don't understand why. Unless there is a rationale to that (which one?)
this looks arbitrary.
I very often see code like:

if (!$callable instanceof Closure) $callable =
Closure::fromCallable($callable);
$r = ReflectionFunction($callable)

The limitation of described in the RFC will make the equivalent boilerplate
much more complex in order to support 8.1

I would like this to be improved or at least better explained.

Cheers,
Nicolas

Reply via email to