Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115127 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13658 invoked from network); 24 Jun 2021 17:08:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2021 17:08:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E0AC51804C3 for ; Thu, 24 Jun 2021 10:27:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_SBL,URIBL_SBL_A autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 24 Jun 2021 10:27:00 -0700 (PDT) Received: by mail-yb1-f174.google.com with SMTP id m9so384897ybo.5 for ; Thu, 24 Jun 2021 10:27:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=RnxE1oPoOGth0XHldVeygju57u8kaH8HRBR/iboX5Jo=; b=Uq0hUCzQ/Lgj6K5nAmLNZyPcwPuI5JTA1EX5OVOrLAiCzXDsINrMuaerF3DsLFx5fA qYIa87on5FOXp2tEAyMUUcSdZlBQ0cins9joNtB9PgZIBADEQbDZtmi2mabIMMaIRmzr LMvLqHVcwB0Dg8d92mJSGe87J52uVVsGif5OY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=RnxE1oPoOGth0XHldVeygju57u8kaH8HRBR/iboX5Jo=; b=QmIsqeaAFDA1tqdqOC0aCcbJ56pAnwx33K5Q40VqAu6q32ziI7/xZU9UXKca9Xz96Z l5qG52qds97RSVNiG2qj1BJEo6nQwCzqu+y+jvy0A8/NyHLilX0lHm28y4PTBv/hfBD7 dWm3vgjWrnZik4lxz0zj+lseLbeUgowe6auwt+5wWgDWgIJGV1UVzO9kJzn1ougCSiT/ 4pD+wozl0Ejw3Cln3k1rx6LZK/9nTsG2v+V8ZYq4/7wrQMnelYjXz51D87ahj0buPuwj m7LMRgpA6OXkt7jfC19HZ3Ga8vKfk88LIzJ2M9rjoKJxjIjT8JSt3Ks8RpXTCiNbf4nT TS/A== X-Gm-Message-State: AOAM532trKrPzAjAI5FAHhUpJ5OKPe8PP/ibIZk3jJN8BP8HuuyCG1af X3xqVN911MpvuaTK7FfCTbl+Pqx0J1p1o3yNnsarXA== X-Google-Smtp-Source: ABdhPJyBA7PUL4QHmr1aOcK8DrnXqdw7BnZ+NQA+Qo5X8ukwRt3mXvxU88kU1QAtVH7K9ieTd9viFYCcAhMWRL+7uYw= X-Received: by 2002:a25:e803:: with SMTP id k3mr6240149ybd.268.1624555618034; Thu, 24 Jun 2021 10:26:58 -0700 (PDT) MIME-Version: 1.0 References: <222b3921-3d9b-47f9-8d13-e6a123f36fad@www.fastmail.com> <919141bc-9b59-48f4-929f-6f0434dd7317@www.fastmail.com> In-Reply-To: Reply-To: Levi Morrison Date: Thu, 24 Jun 2021 11:26:47 -0600 Message-ID: To: Claude Pache Cc: Larry Garfield , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Vote] Partial Function Application From: internals@lists.php.net ("Levi Morrison via internals") On Thu, Jun 24, 2021 at 11:12 AM Claude Pache wrot= e: > > > > > Le 24 juin 2021 =C3=A0 18:02, Larry Garfield a= =C3=A9crit : > > > > 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 explor= e > >> 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 p= ost 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 h= ad 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 =3D> nor= malize_path($request) > |> fn(ServerRequestInterface $request): ServerRequestInterface =3D> oau= th_check($request) > |> fn(ServerRequestInterface $request): ServerRequestInterface =3D> par= se_body($dbconn, $request) > |> fn(ServerRequestInterface $request): ServerRequestInterface =3D> $re= solver->resolveController($request) > |> fn(ServerRequestInterface $request): ResponseInterface =3D> controll= er_caller($request) > |> fn(ResponseInterface $response): ResponseInterface =3D> response_han= dler($response, $theme_system) > |> fn(ResponseInterface $response): ResponseInterface =3D> $add_cache_h= eaders($response) > |> fn(ResponseInterface $response): ResponseInterface =3D> send_respons= e($response) > ; > ``` > > I would write it the following way: > > ``` > Request::fromGlobals() > |> fn($_) =3D> normalize_path($_) > |> fn($_) =3D> oauth_check($_) > |> fn($_) =3D> parse_body($dbconn, $_) > |> fn($_) =3D> $resolver->resolveController($_) > |> fn($_) =3D> controller_caller($_) > |> fn($_) =3D> response_handler($_, $theme_system) > |> fn($_) =3D> $add_cache_headers($_) > |> fn($_) =3D> 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 d= ifference in readability. > > Also, without pipes or partials, it could be written as: > > ``` > $_ =3D Request::fromGlobals(); > $_ =3D normalize_path($_); > $_ =3D oauth_check($_); > $_ =3D parse_body($dbconn, $_); > $_ =3D $resolver->resolveController($_); > $_ =3D controller_caller($_); > $_ =3D response_handler($_, $theme_system); > $_ =3D $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.) > > =E2=80=94Claude 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.