Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127035 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 250D01A00BC for ; Thu, 3 Apr 2025 17:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743701826; bh=hKaBvSusCzm//AIVB1GlGL1fqAzn434JPXtnsRnA5yU=; h=References:In-Reply-To:From:Date:Subject:To:From; b=cBje6N9Ad3IMGGfIKkAa+9epBu5PjxirxB3h9S4QWIuF7qToyhPun5wtgRrTupjri eZGf9JN/oCZkXcqitWAfbG7/W89+scwqotQdw0dx3wmjotP/hKcqRJOkaSzgvh7U8h dSR7Wm16a7dB3f/3B5XN7EIyR/4JCKtFFhoA1anQClt3qCutqc15ArF2jAeqHzN9Y3 EoZvDByYdVGNb/iSHe90FaYQEfrmgm0PS8EYnHf/1r3SM2/nzG49eRF1yTOsvDVbou Uy3hMlRW4OijUis7tWEDsrT43ynaaBG/xZdvDJtM1gNd93JydPB62ZVjBp4jDJYBV9 0+l9YsSo4R1HQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E94F418006C for ; Thu, 3 Apr 2025 17:37:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 3 Apr 2025 17:37:05 +0000 (UTC) Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-7c08f9d0ef3so63331585a.2 for ; Thu, 03 Apr 2025 10:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743701971; x=1744306771; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hKaBvSusCzm//AIVB1GlGL1fqAzn434JPXtnsRnA5yU=; b=JSMkwLmBOBqYdtQfki4E81GJpaIMMcT6YvEQJwCQq5c0weoAP6y057WOJKy7t2eB+6 dxZLU0+3ZiTMQm7+BEudZlraOmtCm2Y41eUrCdEoo3v/7mfbsB7+6BVCAI51TXH+233X kHmDmsvLk2NVC96y/ajK5e29vbkj0Z8fklvWSZxg0f0+Q+4fYq9VyY8RswkJPFagn8Bn 4cdKrJL0ksy5RkYGrNPqWZenATHd5VKMFtn7JwZ4VPoVl6/pBxNpbkiHB0Rsj1iPriR7 va95UOOmQhqyEtL6moVTZiQA0TQ9q4x4lJAwQB2zUH/PxH3vXhjwuDBZ3nUTuMEAVtNA gSrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743701971; x=1744306771; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hKaBvSusCzm//AIVB1GlGL1fqAzn434JPXtnsRnA5yU=; b=EGvWZkA2i3E6bRkw6JKwWZQdHrObmnm8VoU844QgMSJEWG0MMhVH53DYeLtfhIwcTb QUKqYf8fTTHzqUVx4S1d8Om7oQnEKgI51XUS+4Hfwx2PBevR10JXjxnCGXACxqeAaC6P ztKVpOEmVdZNNTozJlZrZB5IXxISFSXCZLnSh0Jx2UPXB0dNh5/IRCtXZcRV5nsZQyMQ XldCXKKzS5f2lj4lW0+L0qyeduoajnDVVoPdMIcJyBvWt4UGVxcnV8O7QpWelADfW8UJ n8seujF9XMeK9FKbHssopmjaJ/B3vNu/SVYDrrgt85ka1t6kgfawPKghtqf526seQ6HV dFeQ== X-Gm-Message-State: AOJu0YyZzhFJGzRfNbVCY4iRxdsWGcORdTPT6pYv3sFj3kOXdo334AqC r3mlS85NKEJabLz1kk0NUG38phOfDbo+HEQ7deKkR+4aZxWkf4wLLcLILO//p5XyjqKsPWPioec Fz3NX6zp8dCcSpU8ToVvG4hhix8y1xS5Umlg= X-Gm-Gg: ASbGncvS9k9zq2MnfHDY8Is0AiDrqgWp+LEhVeGqQTTqXcWMXvDA+Rb1G5baANo55Ml aF/Rk2qp1RZAPcnH5lQ2FvjH3cQ0YqMCZ9NE6SEyGFxwSS7i2VUSC3DtjWbtLnyg8gwDR40dh3o quei47aYSaYaOtCylWS9h6CqUFj078JNfWUFJvKCzKKoZSky/GL7sWj8xWVA== X-Google-Smtp-Source: AGHT+IEamD9tel28M4cRMAFaxdstCVh8axw2tI6lAn6BQkSCunFTStUpFc/8tzL/vTOUDTQbVRRj7fXK3c350NW2H4g= X-Received: by 2002:a05:620a:24c6:b0:7c5:61bc:70ee with SMTP id af79cd13be357-7c774e3961fmr5332385a.52.1743701970818; Thu, 03 Apr 2025 10:39:30 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <5efa2f02-dd1d-4d59-ae07-c75f193b4096@app.fastmail.com> <92b7f1ea-900b-4438-bed7-3fd766bb2d61@rwec.co.uk> In-Reply-To: <92b7f1ea-900b-4438-bed7-3fd766bb2d61@rwec.co.uk> Date: Thu, 3 Apr 2025 19:39:19 +0200 X-Gm-Features: ATxdqUFKE0TBaXZkwmjaKLV7nfQPKpbz0VibyLPQTfYQHK7MHrmxeqakJK96XJQ Message-ID: Subject: Re: [PHP-DEV] [RFC] Pipe Operator (again) To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Rowan On Thu, Apr 3, 2025 at 1:59=E2=80=AFPM Rowan Tommins [IMSoP] wrote: > > At first, I thought Ilija's example looked pretty neat, but having > thought about it a bit more, I think the "first-arg" approach makes a > handful of cases nicer at the cost of a lot of magic, and making other > cases worse. I think "handful" is the word to focus on. As noted, I believe the primary use-case for pipes are iterators. If that's true, then an implicit first-arg approach should cover the majority of examples, while complicating the rest. Whether that's a worthwhile trade-off is for the community to decide. To me, pipes improve readability when they behave like methods, i.e. they perform some operation on a subject. This resembles Swift's protocol extensions or Rust's trait default implementations, except using a different "method" call operator. With this mental model, the first-arg approach seems intuitive to me. Once parameters are out of order, the pipe examples with partial function application cause more cognitive overhead for me, but this is entirely subjective. > If we have a special case where the right-hand side *is* an expression, > evaluated as a single-argument callable/Closure, that's even more scope > for confusion. [cf my thoughts in the async thread about keeping the > right-hand side of "spawn" consistent] To clarify: I'm not in favor of this syntax either. While I originally mentioned it as a possibility, I later noted that `lhs |> {rhs}` would be less ambiguous, given that {} is not legal in the general expression context, while also resembling the `lhs->{rhs}` syntax to a degree. However, because {} is not simpler than `lhs |> rhs()`, I mentioned neither in my e-mail. > The cases it makes nicer are where you are chaining existing functions > with the placeholder as first (but not only) parameter. If we decide not to add an iterator API that works well with first-arg, then I agree that this is not the right approach. But if we do, then neither of your examples are problematic. > // first-arg chaining > $someChain |> fn($string) =3D> explode(':', $string)(); As for string functions, I had a quick look through the stubs and could only find a handful of functions that are not already subject-first: * preg_*/mb_ereg* * mb_split * explode Maybe my search was flawed, let me know if there are any that I missed. explode() specifically usually appears first in a chain (or deepest in nested calls), which means it could just remain a normal function call. $result =3D explode(' ', $str) |> filter(...) |> map(...) |> join(' '); The iterator API would improve the array_filter() example. Admittedly, you might not always want to use iterators. A single array_map() would likely be faster than going through the iterator API. But then again, single calls aren't chains, so they won't benefit much from pipes to begin with. Ilija