Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119678 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4443 invoked from network); 10 Mar 2023 19:04:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Mar 2023 19:04:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7B22F1804DF for ; Fri, 10 Mar 2023 11:04:41 -0800 (PST) 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.2 required=5.0 tests=BAYES_40,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, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 10 Mar 2023 11:04:38 -0800 (PST) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-53916ab0c6bso115820747b3.7 for ; Fri, 10 Mar 2023 11:04:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678475077; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=EGXnk6ERxRM5vtmN4Y7G6UnvtSnqTmuoVakjLPf89K0=; b=jiTOLCPA+d2VM4OVMm8tQoAYPsZKBU4mF8J2cij75yJe+DxxVoCeQJQ1IM539VPT02 J8KPsXVkxNxd7sazDXk1rc1TyI2KxywvGOc8tZzmuAi7XE0UbR71C5x4nHZX+wSHIjRT gao6sv6MoI9TWIRn/jse0VAkOv6XeSi0rC62aO6V+kIDLEnhSlAxEFa60kOnsJzntRrR o7KaLFqBP3seX+wXMUyzRZKMiHAKq49vHpGQBw0u5cfuZma3+D8l/270uVhiHMB4uG10 0NwF1pMC5RMflzDhNkFumvrzlKOJSAUpatPUwMXqMBKoxp2oKBTORVBM5D6vAQ389gu2 hzqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678475077; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EGXnk6ERxRM5vtmN4Y7G6UnvtSnqTmuoVakjLPf89K0=; b=LnMVVw8RIhIvGJapjhS62cRXFRBV+1+JdRk0WmQxLYkoV2gFYb0LujxlFhYlZPlEao 53EUOmh5I9kk6OM53Ri42XlK9TmS/Jatpc5XyYKxJsfLMCsFH+PTlzuOtskRrsfQDc4C 6Rw8XqQOoIFin61KhO9Y7JdogfjxR4jHo9lZQDwjXZKxi3++uO+7l5j/8eDMD0kBTVCr PiVLy+icFjFPWL4O+ccpv3FxyVdnb6TPzQWoTtKBJFELt1E3TzCg1zGy0SdxWXKVZfPX 7pjkSq6NWPUg7jgzmSQZJFnfR8nL0Dp4s+8kvuiM/8+FeOtlWK6pk/iQbW8LPn0ILqL0 ZyYA== X-Gm-Message-State: AO0yUKU5MkTJjmoVWstd6Ws5NTYlGuJBMu6+7xY03STQYARYVTgPLGgA 7cn+jdztA57wA7yL6BhoYKo+nGsWDL+8bUXqmrQ7kqLqv9vN5Q== X-Google-Smtp-Source: AK7set/nV5A2DleXj37mrUKwEv3FWD4YAbvAxnenqAHmfl69mxIJjtoSXWMc6OimN6s2VI8nWeJw954JsfOv/jc+1Sw= X-Received: by 2002:a81:4326:0:b0:535:18be:4127 with SMTP id q38-20020a814326000000b0053518be4127mr16600053ywa.1.1678475077001; Fri, 10 Mar 2023 11:04:37 -0800 (PST) MIME-Version: 1.0 Date: Fri, 10 Mar 2023 21:04:26 +0200 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000baa64505f6906e0c" Subject: First-class callable partial application From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000baa64505f6906e0c Content-Type: text/plain; charset="UTF-8" Hello internals! I'm just wondering why First class callable syntax doesn't allow partial application? Recently I stumbled across following scenario where it could be really useful: ``` public function __invoke(SendOtpCommand $command) { $this->cache->get($command->getPhone(), $this->storeOtp($command, ...)); } private function storeOtp(SendOtpCommand $command, ItemInterface $item) { // some logic } ``` In this example, I supposed that the closure created will accept a single parameter $item, and when it is called back, method storeOtp will accept both $command and $item. As it turned out to be, it doesn't really work this way. Another simplified example: ``` // partial application foo(bar(1, ...)); function foo(Closure $closure) { $closure(2); } function bar(int $a, int $b) { var_dump($a, $b); // 1, 2 } ``` Closure in foo accepts only one parameter. But when it is actually dispatched, bar is called with two arguments. Are there any pitfalls, which prevent implementation of this nifty feature? --000000000000baa64505f6906e0c--