# [RFC] Partial function application

- Thread: https://staging.externals.io/message/114157
- Original archive: https://news-web.php.net/php.internals/114157
- Started by Larry Garfield on 2021-04-25T19:25:42+00:00
- Messages: 68
- RFC: Partial Function Application (Declined) — https://staging.externals.io/rfc/partial_function_application.md
- Page 1 of 3: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://staging.externals.io/message/114157.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #114157 — Larry Garfield — 2021-04-25T19:25:42+00:00

URL: https://staging.externals.io/message/114157#114157

Greetings, Internalians!

I would like to offer for your consideration another RFC, specifically syntax for partial function application.

https://wiki.php.net/rfc/partial_function_application

It includes an implementation by Joe Watkins that is already about 95% complete.  (There's some edge cases he's still sorting out, but all of the typical cases should work already.)  Most of the design work comes from Levi Morrison and Paul Crovella.  I helped out with the tests, a few edge bits, and general instigator/nudge. :-)

Discuss.

-- 
  Larry Garfield
  larry@garfieldtech.com

---

## #114160 — olleharstedt@gmail.com — 2021-04-25T19:50:49+00:00

URL: https://staging.externals.io/message/114157#114160 · In reply to: #114157

2021-04-25 21:25 GMT+02:00, Larry Garfield <larry@garfieldtech.com>:
> Greetings, Internalians!
>
> I would like to offer for your consideration another RFC, specifically
> syntax for partial function application.
>
> https://wiki.php.net/rfc/partial_function_application
>
> It includes an implementation by Joe Watkins that is already about 95%
> complete.  (There's some edge cases he's still sorting out, but all of the
> typical cases should work already.)  Most of the design work comes from Levi
> Morrison and Paul Crovella.  I helped out with the tests, a few edge bits,
> and general instigator/nudge. :-)
>
> Discuss.
>
> --
>   Larry Garfield
>   larry@garfieldtech.com
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>

Nice. :) Are there any other motivating use-cases besides pipe
operator (that are relevant for web dev)?

Olle

---

## #114164 — Max Semenik — 2021-04-25T21:07:27+00:00

URL: https://staging.externals.io/message/114157#114164 · In reply to: #114160

On Sun, Apr 25, 2021 at 10:26 PM Larry Garfield <larry@garfieldtech.com>
wrote:

> https://wiki.php.net/rfc/partial_function_application


 Amazing, I've wanted this for so long! Have you considered extending this
syntax to OOP, e.g. $obj->method(?) or SomeClass::staticMethod(?)?

On Sun, Apr 25, 2021 at 10:51 PM Olle Härstedt <olleharstedt@gmail.com>
wrote:

> Nice. :) Are there any other motivating use-cases besides pipe
> operator (that are relevant for web dev)?


One reason I'm personally excited about this proposal is that it would
allow static analysis in more cases, e.g.

$param = 'fooBar'; // What's this string? A user name? Elon Musk's favorite
color? Text of US Constitution?

somefunc($param);

function somefunc($cb) {
    $cb(123, 'meh'); // What parameter types does this accept?
}

Allowing syntax like $param = fooBar(?, ?); would indicate clearly what
this variable receives. Analysis tools would then be able to check if such
a function exists and whether it would receive parameters of expected types.

-- 
Best regards,
Max Semenik

---

## #114166 — olleharstedt@gmail.com — 2021-04-25T21:30:57+00:00

URL: https://staging.externals.io/message/114157#114166 · In reply to: #114164

2021-04-25 21:07 GMT, Max Semenik <maxsem.wiki@gmail.com>:
> On Sun, Apr 25, 2021 at 10:26 PM Larry Garfield <larry@garfieldtech.com>
> wrote:
>
> > […]
>
>
>  Amazing, I've wanted this for so long! Have you considered extending this
> syntax to OOP, e.g. $obj->method(?) or SomeClass::staticMethod(?)?
>
> On Sun, Apr 25, 2021 at 10:51 PM Olle Härstedt <olleharstedt@gmail.com>
> wrote:
>
> > […]
>
>
> One reason I'm personally excited about this proposal is that it would
> allow static analysis in more cases, e.g.
>
> $param = 'fooBar'; // What's this string? A user name? Elon Musk's favorite
> color? Text of US Constitution?
>
> somefunc($param);
>
> function somefunc($cb) {
>     $cb(123, 'meh'); // What parameter types does this accept?
> }
>
> Allowing syntax like $param = fooBar(?, ?); would indicate clearly what
> this variable receives. Analysis tools would then be able to check if such
> a function exists and whether it would receive parameters of expected
> types.

Like an alternative to value objects (`class Email ... `)? Not sure I
understand how, sorry.

Olle

---

## #114167 — olleharstedt@gmail.com — 2021-04-25T21:34:12+00:00

URL: https://staging.externals.io/message/114157#114167 · In reply to: #114164

2021-04-25 21:07 GMT, Max Semenik <maxsem.wiki@gmail.com>:
> On Sun, Apr 25, 2021 at 10:26 PM Larry Garfield <larry@garfieldtech.com>
> wrote:
>
> > […]
>
>
>  Amazing, I've wanted this for so long! Have you considered extending this
> syntax to OOP, e.g. $obj->method(?) or SomeClass::staticMethod(?)?
>
> On Sun, Apr 25, 2021 at 10:51 PM Olle Härstedt <olleharstedt@gmail.com>
> wrote:
>
> > […]
>
>
> One reason I'm personally excited about this proposal is that it would
> allow static analysis in more cases, e.g.
>
> $param = 'fooBar'; // What's this string? A user name? Elon Musk's favorite
> color? Text of US Constitution?
>
> somefunc($param);
>
> function somefunc($cb) {
>     $cb(123, 'meh'); // What parameter types does this accept?
> }
>
> Allowing syntax like $param = fooBar(?, ?); would indicate clearly what
> this variable receives. Analysis tools would then be able to check if such
> a function exists and whether it would receive parameters of expected
> types.
>
> --
> Best regards,
> Max Semenik
>

By the way, for pipe operators to be really useful, it should probably
be possible to combine with middleware.

Olle

---

## #114168 — Levi Morrison via internals — 2021-04-25T21:34:46+00:00

URL: https://staging.externals.io/message/114157#114168 · In reply to: #114164

>
> On Sun, Apr 25, 2021 at 10:26 PM Larry Garfield <larry@garfieldtech.com>
> wrote:
>
> > […]
>
>
>  Amazing, I've wanted this for so long! Have you considered extending this
> syntax to OOP, e.g. $obj->method(?) or SomeClass::staticMethod(?)?

It works for methods as well, as stated in the proposal section. I
think there aren't any examples in the RFC just because functions make
for shorter examples ^_^  but we should add some to help make that
clear.

---

## #114170 — Larry Garfield — 2021-04-25T22:18:17+00:00

URL: https://staging.externals.io/message/114157#114170 · In reply to: #114168

> 
> > […]
> 
> It works for methods as well, as stated in the proposal section. I
> think there aren't any examples in the RFC just because functions make
> for shorter examples ^_^  but we should add some to help make that
> clear.

Ha, yes, I didn't realize we were missing those. :-)  I just added a Methods section.  In short, yes, it works for methods, functions, closures, basically anything you can otherwise call.

--Larry Garfield

---

## #114171 — Larry Garfield — 2021-04-25T22:19:44+00:00

URL: https://staging.externals.io/message/114157#114171 · In reply to: #114167

> By the way, for pipe operators to be really useful, it should probably
> be possible to combine with middleware.
> 
> Olle

Pipes are their own RFC I plan to bring back up after this one gets closer to a vote or passes, as they complement each other nicely.  I'm not sure what you mean here, though.  Pipes *are* a middleware style, just a different approach than the deeply nested call stack that is typical today.

--Larry Garfield

---

## #114179 — olleharstedt@gmail.com — 2021-04-26T07:39:42+00:00

URL: https://staging.externals.io/message/114157#114179 · In reply to: #114171

2021-04-26 0:19 GMT+02:00, Larry Garfield <larry@garfieldtech.com>:
> 
>
>
> > […]
>
> Pipes are their own RFC I plan to bring back up after this one gets closer
> to a vote or passes, as they complement each other nicely.  I'm not sure
> what you mean here, though.  Pipes *are* a middleware style, just a
> different approach than the deeply nested call stack that is typical today.
>
> --Larry Garfield

I was thinking of middleware as defined in PSR (since that's what
middleware frameworks are built on). Would be nice with a connection
there.

Olle

---

## #114184 — Lynn — 2021-04-26T08:44:31+00:00

URL: https://staging.externals.io/message/114157#114184 · In reply to: #114157

On Sun, Apr 25, 2021 at 9:26 PM Larry Garfield <larry@garfieldtech.com>
wrote:

> Greetings, Internalians!
>
> I would like to offer for your consideration another RFC, specifically
> syntax for partial function application.
>
> https://wiki.php.net/rfc/partial_function_application
>
> It includes an implementation by Joe Watkins that is already about 95%
> complete.  (There's some edge cases he's still sorting out, but all of the
> typical cases should work already.)  Most of the design work comes from
> Levi Morrison and Paul Crovella.  I helped out with the tests, a few edge
> bits, and general instigator/nudge. :-)
>
> Discuss.
>
> --
>   Larry Garfield
>   larry@garfieldtech.com
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>
Heya, this is an interesting feature!

The way I understand it, it adds the ability to turn a call to an object
method into a callable?
```php
class CategorizedThings {
    private array $theThings = [];
    public function addOneThing(mixed $thing, string $category): void {
        $this->theThings[$category] = $thing;
    }
}

$things = new CategorizedThings();
$adder = $things->addOneThing(?, 'a category');

foreach ($repository->findAll() as $aThing) {
    $adder($aThing);
}

// which would be the same as:

$things = new CategorizedThings();
$adder = function (mixed $aThing) use ($things) {
    $things->addOneThing($aThing, 'a category');
}

foreach ($repository->findAll() as $aThing) {
    $adder($aThing);
}
```

I assume the following would also be possible?
```php
class Something {
    public static function toString(mixed $v): string {
        return (string) $v;
    }
}

function toString(mixed $v) : string {
    return (string) $v;
}

array_map(Something::toString(?), [1, 2, 3]);
array_map(toString(?), [1, 2, 3]);
// instead of
array_map([Something::class, 'toString'], [1, 2, 3])
array_map('toString', [1, 2, 3]);
```

If this is indeed the scenario, would it be worth adding a syntax to
indicate _all_ parameters can be placeholders? When a signature has
multiple arguments, `toString(?, ?, ?, ?)` could become `toString(...?)` or
maybe something like `toString(*)`?

---

## #114189 — Levi Morrison via internals — 2021-04-26T13:42:34+00:00

URL: https://staging.externals.io/message/114157#114189 · In reply to: #114184

> If this is indeed the scenario, would it be worth adding a syntax to
> indicate _all_ parameters can be placeholders? When a signature has
> multiple arguments, `toString(?, ?, ?, ?)` could become `toString(...?)` or
> maybe something like `toString(*)`?

At the moment, there isn't any difference in `foo(?)` and `foo(?, ?,
?, ?, ?, ?, ?, ?)`. If there is one placeholder, then it will bind (or
fix) the non-placeholder arguments and then create a closure-like with
a signature of the remaining parameters. Adding more placeholders does
not change anything, except to adjust positions:

  foo(?, $bar, ?, $baz)

In this case the two placeholders are meaningful because they adjust
which positional arguments are bound. This is the only difference in
behavior in one placeholder or more.

In an earlier version of the RFC I had `...` so you could write
`foo(...)`. Some of the RFC authors didn't like this, because it was
functionally no different and brought up "when to use ? and when to
use ..." as a question.

---

## #114190 — Levi Morrison via internals — 2021-04-26T14:16:26+00:00

URL: https://staging.externals.io/message/114157#114190 · In reply to: #114160

>
> 2021-04-25 21:25 GMT+02:00, Larry Garfield <larry@garfieldtech.com>:
> > […]
>
> Nice. :) Are there any other motivating use-cases besides pipe
> operator (that are relevant for web dev)?
>
> Olle
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>

Yes, of course! PHP has many uses of `array_map`, `array_filter`, etc,
that take a callback as a parameter. It's hard to create good examples
on the spot, but here's an example, at least:

    array_filter($array, in_array(?, $haystack, strict: true))

---

## #114401 — Larry Garfield — 2021-05-11T15:38:49+00:00

URL: https://staging.externals.io/message/114157#114401 · In reply to: #114157

> Greetings, Internalians!
> 
> I would like to offer for your consideration another RFC, specifically 
> syntax for partial function application.
> 
> https://wiki.php.net/rfc/partial_function_application
> 
> It includes an implementation by Joe Watkins that is already about 95% 
> complete.  (There's some edge cases he's still sorting out, but all of 
> the typical cases should work already.)  Most of the design work comes 
> from Levi Morrison and Paul Crovella.  I helped out with the tests, a 
> few edge bits, and general instigator/nudge. :-)
> 
> Discuss.

It looks like the conversation has died down, and it's been two weeks, so pending any other notable feedback I'll open a vote on this RFC on Thursday or Friday.

--Larry Garfield

---

## #114412 — Nicolas Grekas — 2021-05-11T16:57:45+00:00

URL: https://staging.externals.io/message/114157#114412 · In reply to: #114401

> 
> > […]
>
> It looks like the conversation has died down, and it's been two weeks, so
> pending any other notable feedback I'll open a vote on this RFC on Thursday
> or Friday.
>
> --Larry Garfield
>

LGTM, thanks for the RFC!

What about visibility? I suppose this works even outside the object scope?
should this be mentionned?
$foo = $this->somePrivateMethod(1, ?)

Would it make sense to support a way to use a placeholder for "all
remaining args"?
Eg:
$foo = some_func(1, ...?)

Combined with my previous comment, this could replace
Closure::fromCallable() by a language construct, which is something that we
already discussed in another thread (we talked about some ::function
special suffix instead):
$foo = $this->somePrivateMethod(...?)

In this last form, we might make this result in Closure::fromCallable()
exactly. Aka no increase of the depth of the stack trace.

BTW, ideally, partial functions should not increase the depth of the
stacktrace at all. Do they?

Nicolas

---

## #114414 — David Gebler — 2021-05-11T16:59:18+00:00

URL: https://staging.externals.io/message/114157#114414 · In reply to: #114401

On Tue, May 11, 2021 at 4:39 PM Larry Garfield <larry@garfieldtech.com>
wrote:

> It looks like the conversation has died down, and it's been two weeks, so
> pending any other notable feedback I'll open a vote on this RFC on Thursday
> or Friday.
>
> --Larry Garfield
>
>
>
 My only query / point of consideration is a very minor one for what is
otherwise an enthusiastic (non-voting) +1. In relation to one of the
examples:

function whole($one, $two) { /* ... */ }
// equivalent to calling whole(1, 2, 3)
$result = whole(?, 2)(1, 3);

Is there a risk this has the potential to be confusing? We've always had
this quirk in PHP of being able to pass extra unspecified parameters in
function calls, but with the exception of variadic functions the
expectation is that they are ignored. Arguably if I saw this:

function whole($one, $two) { /* ... */ }
$partial = whole(?, 2);
$result = partial(1, 3);

I might expect it to semantically translate to:

function partial($one) { return whole($one, 2); }

with the extra parameter, 3, ignored as per convention for any other
function receiving undefined extra params. But the RFC says this parameter
would be passed to whole(). Which is not unreasonable, but yeah I guess it
strikes me it's kind of a quirk in itself to do it that way.

-Dave

---

## #114417 — Larry Garfield — 2021-05-11T17:55:12+00:00

URL: https://staging.externals.io/message/114157#114417 · In reply to: #114412

> > […]
> 
> LGTM, thanks for the RFC!
> 
> What about visibility? I suppose this works even outside the object scope?
> should this be mentionned?
> $foo = $this->somePrivateMethod(1, ?)

We're pretty sure it will work, and if you return $foo to another caller and then call it, it will work fine.  We'll add a test to confirm that.

> Would it make sense to support a way to use a placeholder for "all
> remaining args"?
> Eg:
> $foo = some_func(1, ...?)

That's already implicit in the way it works now.  If you placeholder at least one parameter, and then don't fill in all of the remaining parameters, any additional trailing parameters are always placeholdered.  So $obj->foo(?) will always return a partial that has the same arity as foo() does, regardless of how many parameters it has.

> Combined with my previous comment, this could replace
> Closure::fromCallable() by a language construct, which is something that we
> already discussed in another thread (we talked about some ::function
> special suffix instead):
> $foo = $this->somePrivateMethod(...?)

Yep.  That's noted in the RFC.  Although not the primary intent, a nice side effect is that any_func(?) is now a safe way to turn any function/method into a callable to reference it.  That renders ::function or similar 98% unnecessary.  (The remaining cases are mostly where you need to collect data statically for compilation or similar.)

> In this last form, we might make this result in Closure::fromCallable()
> exactly. Aka no increase of the depth of the stack trace.
> 
> BTW, ideally, partial functions should not increase the depth of the
> stacktrace at all. Do they?
> 
> Nicolas

They currently do, since they work by creating a Closure-esque object called Partial with an __invoke() method.  However, if you partial the same thing multiple times then only one stack level gets added.  That is:

function test($a, $b, $c, $d) { throw new Exception(); }

$first = test(?, ?, ?, ?);
$second = $first(1, ?);
$third = $second(2, ?);
$fourth = $third(3, ?);
$result = $fourth(4);

The stack at the end will contain only one partial "level", not 4.

--Larry Garfield

---

## #114419 — Nicolas Grekas — 2021-05-11T18:32:24+00:00

URL: https://staging.externals.io/message/114157#114419 · In reply to: #114417

> > […]
> specifically
> > […]
> 95%
> > […]
> of
> > […]
> comes
> > […]
> so
> > […]
> Thursday
> > […]
> scope?
> > […]
>
> We're pretty sure it will work, and if you return $foo to another caller
> and then call it, it will work fine.  We'll add a test to confirm that.
>
> > […]
>
> That's already implicit in the way it works now.  If you placeholder at
> least one parameter, and then don't fill in all of the remaining
> parameters, any additional trailing parameters are always placeholdered.
> So $obj->foo(?) will always return a partial that has the same arity as
> foo() does, regardless of how many parameters it has.
>
> > […]
> we
> > […]
>
> Yep.  That's noted in the RFC.  Although not the primary intent, a nice
> side effect is that any_func(?) is now a safe way to turn any
> function/method into a callable to reference it.  That renders ::function
> or similar 98% unnecessary.  (The remaining cases are mostly where you need
> to collect data statically for compilation or similar.)
>

Great news!

> In this last form, we might make this result in Closure::fromCallable()
> > […]
>
> They currently do, since they work by creating a Closure-esque object
> called Partial with an __invoke() method.  However, if you partial the same
> thing multiple times then only one stack level gets added.
>

Nice. Would it be possible to optimize this and remove the extra frame? At
least maybe for the (?) case?

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

---

## #114422 — Larry Garfield — 2021-05-11T19:53:37+00:00

URL: https://staging.externals.io/message/114157#114422 · In reply to: #114419

> > […]
> 
> Nice. Would it be possible to optimize this and remove the extra frame? At
> least maybe for the (?) case?

I'd have to defer to Joe (he wrote the implementation), but I suspect not.  The partial has to be there to carry around the information of what callable to actually call and what the bound parameters are.  At that point, it's likely more work to decompose the Partial internally before calling it than to just call the Partial itself.

> 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.

--Larry Garfield

---

## #114425 — drealecs@gmail.com — 2021-05-12T05:26:35+00:00

URL: https://staging.externals.io/message/114157#114425 · In reply to: #114417

Hi Larry,

On Tue, May 11, 2021 at 8:55 PM Larry Garfield <larry@garfieldtech.com>
wrote:

>
> They currently do, since they work by creating a Closure-esque object
> called Partial with an __invoke() method.
>
> --Larry Garfield
>
>
1. Would it be possible to mention the `Partial` class in the RFC? From
what I understand this is what it will be returned by the
`get_class($partial)`.
I guess the class will be final (similar with Closure) and will only have a
private constructor and a public __invoke method.

2. As now ReflectionFunction accepts Closure|string, wouldn't it be simpler
for the users to just have it accept Closure|Partial|string to avoid
introducing another reflection class and also avoid the userland issue you
mentioned?

Alex

---

## #114436 — Nicolas Grekas — 2021-05-12T09:51:00+00:00

URL: https://staging.externals.io/message/114157#114436 · In reply to: #114422

> > […]
> same
> > […]
> At
> > […]
>
> I'd have to defer to Joe (he wrote the implementation), but I suspect
> not.  The partial has to be there to carry around the information of what
> callable to actually call and what the bound parameters are.  At that
> point, it's likely more work to decompose the Partial internally before
> calling it than to just call the Partial itself.
>

Then I suppose that removing the extra frame would mean embedding that
state into Closure objects. Would it make sense to extend Closure this way?
Isn't the new Partial class an implementation artefact that should be
removed? If not, what are the userland-side reasons to keep it?

If the Partial class has to be kept, can it be optimized out back to a
closure when no arguments are bound? (aka the "$closure = $this->method(?)"
case)



> > […]
>
> 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).

Nicolas

---

## #114451 — Larry Garfield — 2021-05-12T16:18:51+00:00

URL: https://staging.externals.io/message/114157#114451 · In reply to: #114436

> > […]
> 
> 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. :-)

--Larry Garfield

---

## #114454 — Nicolas Grekas — 2021-05-12T16:36:50+00:00

URL: https://staging.externals.io/message/114157#114454 · In reply to: #114451

>
> > […]
> Wouldn't
> > […]
> the
> > […]
> string to
> > […]
> returns
> > […]
>
> 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

---

## #114459 — someniatko — 2021-05-13T08:44:54+00:00

URL: https://staging.externals.io/message/114157#114459 · In reply to: #114157

> Greetings, Internalians!
>
> I would like to offer for your consideration another RFC, specifically syntax for partial function application.
>
> https://wiki.php.net/rfc/partial_function_application

Thank you again for one more wonderful language change! I am sure this
is a huge step into the correct direction for the language. One of the
nice side effects of this proposal is that it is great for reducing
visual clutter when being used in functions like `array_map()`,
`array_filter()` etc. However, I have a small nitpick, which may
probably be a bit hard to implement: what about partially applied
constructors? They are sort of functions as well. For instance:

```php
$strings = [ 'value-1', 'value-2' ];
$objects = array_map(
    fn (string $s) => new ValueObject($s),
    $strings
```

to be turned into
```php
$strings = [ 'value-1', 'value-2' ];
$objects = array_map(new ValueObject(?), $strings);
```

There is unfortunately no mention of partially applied constructors in
the RFC. If it is not implemented as above, could you please consider
adding it to the Future Scope probably?

---

## #114461 — Levi Morrison via internals — 2021-05-13T13:44:40+00:00

URL: https://staging.externals.io/message/114157#114461 · In reply to: #114459

>
> > […]
>
> Thank you again for one more wonderful language change! I am sure this
> is a huge step into the correct direction for the language. One of the
> nice side effects of this proposal is that it is great for reducing
> visual clutter when being used in functions like `array_map()`,
> `array_filter()` etc. However, I have a small nitpick, which may
> probably be a bit hard to implement: what about partially applied
> constructors? They are sort of functions as well. For instance:
>
> ```php
> $strings = [ 'value-1', 'value-2' ];
> $objects = array_map(
>     fn (string $s) => new ValueObject($s),
>     $strings
> ```
>
> to be turned into
> ```php
> $strings = [ 'value-1', 'value-2' ];
> $objects = array_map(new ValueObject(?), $strings);
> ```
>
> There is unfortunately no mention of partially applied constructors in
> the RFC. If it is not implemented as above, could you please consider
> adding it to the Future Scope probably?
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>

The GitHub PR supports this, and there is even a comment there saying
we should show this in the RFC. We'll get that updated.

---

## #114462 — Levi Morrison via internals — 2021-05-13T14:30:22+00:00

URL: https://staging.externals.io/message/114157#114462 · In reply to: #114461

On Thu, May 13, 2021 at 7:44 AM Levi Morrison
<levi.morrison@datadoghq.com> wrote:
>
> 
> > […]
>
> The GitHub PR supports this, and there is even a comment there saying
> we should show this in the RFC. We'll get that updated.

I was a bit too hasty. In further review it does do something, but not
what you'd want in situations like this. We are discussing among
authors whether it is technically feasible to support the expected
behavior at this time.

---

Next page: https://staging.externals.io/message/114157.md?page=2
