On Thu, Jun 24, 2021 at 11:12 AM Claude Pache <claude.pa...@gmail.com> wrote:
>
>
>
> > Le 24 juin 2021 à 18:02, Larry Garfield <la...@garfieldtech.com> a écrit :
> >
> > On Wed, Jun 16, 2021, at 11:16 AM, Larry Garfield wrote:
> >> Hi folks.  The vote for the Partial Function Application RFC is now
> >> open, and will run until 30 June.
> >>
> >> https://wiki.php.net/rfc/partial_function_application
> >>
> >> Of particular note, a few people had asked about using ...? instead of
> >> ... for the variadic placeholder.  In the end we decided not to explore
> >> that, as Nikita explained off-list it was actually more confusing, not
> >> less, as it would suggest "placeholder for a variadic" rather than "a
> >> placeholder that is variadic."  Otherwise, it's just more typing.  The
> >> syntax choices section of the RFC has been updated accordingly.
> >
> > Since some people still don't grok the use cases, I've written a blog post 
> > to make the case for them better than a detail-oriented RFC can.
> >
> > https://peakd.com/hive-168588/@crell/the-case-for-partials-and-pipes-in-php
> >
> > There has also been some positive Twitter chatter, as well as the level of 
> > +1s on that post (which is, I think, the highest of any PHP post I've had 
> > on there, ever), so I think the demand for it is definitely there in the 
> > ecosystem.  It's just not people who frequent Internals. :-/
> >
> > I'd say there are definitely people that want to use partials.
> >
> > --Larry Garfield
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: https://www.php.net/unsub.php
> >
>
> Hi,
>
> In the blog post, you are not fair when comparing:
>
> ```
> Request::fromGlobals()
>    |> normalize_path(?)
>    |> oauth_check(?)
>    |> parse_body($dbconn, ?)
>    |> $resolver->resolveController(?)
>    |> controller_caller(?)
>    |> response_handler(?, $theme_system)
>    |> $add_cache_headers(?)
>    |> send_response(?)
> ;
> ```
>
> with:
>
> ```
> Request::fromGlobals()
>   |> fn(ServerRequestInterface $request): ServerRequestInterface => 
> normalize_path($request)
>   |> fn(ServerRequestInterface $request): ServerRequestInterface => 
> oauth_check($request)
>   |> fn(ServerRequestInterface $request): ServerRequestInterface => 
> parse_body($dbconn, $request)
>   |> fn(ServerRequestInterface $request): ServerRequestInterface => 
> $resolver->resolveController($request)
>   |> fn(ServerRequestInterface $request): ResponseInterface => 
> controller_caller($request)
>   |> fn(ResponseInterface $response): ResponseInterface => 
> response_handler($response, $theme_system)
>   |> fn(ResponseInterface $response): ResponseInterface => 
> $add_cache_headers($response)
>   |> fn(ResponseInterface $response): ResponseInterface => 
> send_response($response)
> ;
> ```
>
> I would write it the following way:
>
> ```
> Request::fromGlobals()
>   |> fn($_) => normalize_path($_)
>   |> fn($_) => oauth_check($_)
>   |> fn($_) => parse_body($dbconn, $_)
>   |> fn($_) => $resolver->resolveController($_)
>   |> fn($_) => controller_caller($_)
>   |> fn($_) => response_handler($_, $theme_system)
>   |> fn($_) => $add_cache_headers($_)
>   |> fn($_) => send_response($_)
> ;
> ```
>
> The version with partials is still better as it has less grawlix, but the 
> difference between the two is considerably reduced. Style can make a big 
> difference in readability.
>
> Also, without pipes or partials, it could be written as:
>
> ```
> $_ = Request::fromGlobals();
> $_ = normalize_path($_);
> $_ = oauth_check($_);
> $_ = parse_body($dbconn, $_);
> $_ = $resolver->resolveController($_);
> $_ = controller_caller($_);
> $_ = response_handler($_, $theme_system);
> $_ = $add_cache_headers($_);
> send_response($_);
> ```
> where my `$_`s play the role of your `?`s.
>
> (I still do find that pipes and partials would be nice additions, but it is 
> not something that I am desperately craving after.)
>
> —Claude

Ah, but you've uncovered one of the benefits of partials -- they
propagate type information. Of course, in this case you would hit an
error immediately so it wouldn't make _that_ much of a difference, but
there are cases where it would matter, such as when being used in
callbacks to `array_map` and such.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to