Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114184 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 20842 invoked from network); 26 Apr 2021 08:41:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Apr 2021 08:41:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B785F1804DC for ; Mon, 26 Apr 2021 01:45:02 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 ; Mon, 26 Apr 2021 01:44:59 -0700 (PDT) Received: by mail-io1-f53.google.com with SMTP id t21so4351797iob.2 for ; Mon, 26 Apr 2021 01:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dBJJTI8r2+2E4XaU5ksS54xNfNe9sSTcgZGYlGUWfVM=; b=HKnLBNDEgQbVPvmM06jrHL7jZafAirYiHlM57XyyMVmpieTgXzRSNZpzUsJr3489ei aJYaQU8hub4ig0loRNFjePAE4F54e9TlQGhw1RtrQ/qPVRwL7x71ADgH9xEBmA5x0X0a 22v5taPpkX3JoHcVgUNZegBjA4sdQpGIn+r2X0wd6+7o9WV6ehYmen1wuDelnbDVK1hO 7fpMvvUGa+ZOD6kuMorzX5geXrld0ReHIcY+6gi8toIScaEbG3Jb35OCN9zEK+Mq5dvw EhSYkh/una3KFpLXkjqa/dkKxXaIzLb+RnSPH/qH1NJ0d5Q7GJLCaKuuP/btg0BtWVAH nChQ== 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; bh=dBJJTI8r2+2E4XaU5ksS54xNfNe9sSTcgZGYlGUWfVM=; b=jrl2LiIdLjDzj5lRd9jeUu7F6bNliOi9RgALlDV/nSda96f6fU8X+htYKFuyfxHhzO lTzuz7Xr+cz74hj0CYKyUcrdkicl1QXevu2b9e1LA4cIKi2nP2ZZkjFZyl33oh+5btxD NJqSyNS5R00tz/V3ibbWo7idmebKgrLbARF5kBry8EaQoCNap6iFKhpimSYcUzpGKoFe cCyaDWoRl+y6n9F2JJl+ePPEqk5DvgDgSBBPFKBi5DwL6qxZRXsBFBPNyKM0XqVWJkGu ZcSqzzJBaTemsZXf6iHisU/2B6yHZiZwbMPHSdD1CnfUHuVFJOhG2BeQ2cVLWX+ST358 P+Fg== X-Gm-Message-State: AOAM530mmMHO3bR2/hUUpctkStDvCQ1WNeiz5t821wva7GV25XQEn+YO XfwRB4yWHb7kY9chSwzeqAaWlIUy1gAw8XBLBOKqf7OQglM= X-Google-Smtp-Source: ABdhPJy5ftiDYWI3uNz2YmPn/xuBZclXJmBx2Ad53QtEfv1wESg63NSA+G1cGds1KnDDB49OugZljqYR/RqeyKaqA7I= X-Received: by 2002:a05:6602:3415:: with SMTP id n21mr6218716ioz.120.1619426696222; Mon, 26 Apr 2021 01:44:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 26 Apr 2021 10:44:31 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000f7ddbe05c0dc281c" Subject: Re: [PHP-DEV] [RFC] Partial function application From: kjarli@gmail.com (Lynn) --000000000000f7ddbe05c0dc281c Content-Type: text/plain; charset="UTF-8" On Sun, Apr 25, 2021 at 9:26 PM Larry Garfield 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > 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(*)`? --000000000000f7ddbe05c0dc281c--