[RFC] Partial Function Application, take 2

From: Date: Wed, 02 Jun 2021 17:45:15 +0000
Subject: [RFC] Partial Function Application, take 2
Groups: php.internals 
Request: Send a blank email to internals+get-114694@lists.php.net to get a copy of this message
Hi folks.  After much off-list discussion, iteration, and consideration, we have a new draft of PFA
ready for review.

The URL is the same:

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

It's a bit long because we wanted to be as precise as possible.  However, in short:

* Partial application creates a closure object you can use like any other.
* A ? indicates "exactly one required parameter here"
* A ... indicates "zero or more parameters here"
* If the pattern in the partial is compatible with the underlying function, everything "just
works"
* If it's not compatible, you get an error.
* Named placeholders are not supported.
* Splat (argument unpacking) is not supported.

That gives us the 3 most important use cases, plus many others:

arbitrary_function(...) works to reference any function safely.  (This is what Nikita's
mini-scoped proposal did.)

some_func(1, 2, ?, 5) works to reduce any function to single-argument, which makes it useful in many
callback situations.

any_func($all, $params, ...) works to provide all the arguments to a function but not call it yet;
you can then cal the resulting closure later with no arguments to actually invoke it.

We're reasonably confident that we have all the ins and outs covered, and in a performant way. 
Because it's such a heavy rework, though, we want to give it enough time for the discussion to
settle, so won't call a vote for at least 2 weeks from today (give or take the feedback we get
here).

Cheers!

-- 
  Larry Garfield
  larry@garfieldtech.com


Thread (11 messages)

« previous php.internals (#114694) next »