Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120836 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54106 invoked from network); 18 Jul 2023 15:05:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jul 2023 15:05:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D3A3F1804F2 for ; Tue, 18 Jul 2023 08:05:04 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 18 Jul 2023 08:05:04 -0700 (PDT) Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-1b0748bc78dso4323964fac.0 for ; Tue, 18 Jul 2023 08:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689692704; x=1692284704; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LPPUvWk3tFcS+bEhaGGWGKYh82cIe5Hd2sCzBuEL+Pw=; b=OdvxnB+s4vcFAt65qnCZqrcltkf/mxXUPzTzqJJuj+S/+R0BYefTkwjaY97XqJNlP8 ZzuATbQms5n2ng9lE2ghhdEW2WfrS8bahpaEGoyb5sEfQ9LEciAnlkoj8SKozusellf2 IseJhl+iswFZ018HMC7foNyBW6yO86IltOFyfVBt8KCpfhxPE8lwlNRvvNZunJ0mSGhw gQg4IPcR/Y+dmpn35tdKCVOrtFIbbzcETY7qdMq3MpjqxFDDdLcm3xqwvY58Ot622XhD mkAvbEPH54A0kzg08SQPut/TIem1omOUhVQKM8swomfWPhRUPetdIk5uV+mplWvezqsw jaFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689692704; x=1692284704; h=content-transfer-encoding:cc: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=LPPUvWk3tFcS+bEhaGGWGKYh82cIe5Hd2sCzBuEL+Pw=; b=SAHhubNpZQoZdglZySEXgwnaHLYeWYFz3ygq4kCOrNUSYPKmLga2D3XskCuk4f3guf TZNJDtF8dDREW/KvU4BnqC7R6qqmfU2eAm9uq1qgTWlw/1dwMEJt9bs4EgDfH/h0Y61o TtPQ8soZp5TygezpAxmkyNWkLKWjMMQOMAMLXe5CVuSU017CLLTR0p2SSU/Dag5JHL0P 7U8fbW6fQQF3b96lbexhx58v2GEZnd6SIJo5fwqnfhNsyrBmYvFm8WRXwzXDwzwlIZQJ g37hJbZTrbBx4iTUtExcRA//XxxLnnoYWlyEs3CvFa0plACTcvDwYFZ92uhHRrKUWmR/ Nm/w== X-Gm-Message-State: ABy/qLavu4CWSCCraLf4RkKmPgxAAkKfPg2P5NRkcTbT94vyv5PVBmk7 BxM7WzOOQe+VulijAplfoHqa/8+ZQIFioBer51Vb65hsVok= X-Google-Smtp-Source: APBJJlESiAhB9h3ZUMl6tw+IuR49OmZWGOjU270rHWZf25KgL2uYXqrAqwJci9C45vQfYKQbv1ZdejzvA/EiJc0mFLI= X-Received: by 2002:a05:6870:a11a:b0:1ba:bef6:9d69 with SMTP id m26-20020a056870a11a00b001babef69d69mr1010434oae.5.1689692703521; Tue, 18 Jul 2023 08:05:03 -0700 (PDT) MIME-Version: 1.0 References: <8055b366-32f1-4d2c-85d0-0cf665e6c8d3@app.fastmail.com> In-Reply-To: Date: Tue, 18 Jul 2023 17:04:52 +0200 Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: someniatko , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] pipes, scalar objects and on? From: landers.robert@gmail.com (Robert Landers) On Tue, Jul 18, 2023 at 3:18=E2=80=AFPM Olle H=C3=A4rstedt wrote: > > 2023-07-18 14:48 GMT+02:00, someniatko : > > I am glad this topic arose! I was also planning to write on this topic = to > > the internals mailing list, but have abandoned this idea, because I fee= l it > > might be inconvenient for the real active PHP developers on the list to > > receive too many emails from the people which don't actively participat= e in > > the development itself. > > > > My interest in the pipe operator might seem a little non-standard - > > basically what I'd really want to see is a **nullable** pipe operator! > > > > There is a popular library github.com/schmittjoh/php-option, which has = 250 > > MILLION installations. Basically what it provides is a class-wrapper of= a > > value of lack thereof: it's either `Some` or `None`. I also maint= ain > > a similar library https://packagist.org/packages/someniatko/result-type > > which fixes some shortcomings of the original one related to the static > > analysis, but this is another story. Basically what the stats tell us i= s > > that such stuff is popular among the PHP community. > > > > In my eyes, it is actually semantically equivalent to the nullable PHP > > types: `?Type`. And some operations provided by the lib, are actually > > covered by PHP itself, which has multiple null-friendly operators: > > `$option->getOrElse($defaultVal)` --> `$nullable ?? $defaultVal` > > `$option->isEmpty()` --> `$nullable =3D=3D=3D null` > > `$option->getOrThrow(new \Exception('blah'))` --> `$nullable ?? throw n= ew > > \Exception('blah')` > > > > I'd like to use the arguably "more idiomatic" native PHP nullables, rat= her > > than a foreign-feeling userspace construct, if they were more convenien= t. > > > > But there is a very important operation, `map()`, which is unfortunatel= y > > not covered by the native PHP, which is `Option::map()`, and here is a > > real-world example: > > ``` > > return $repository->getById($idFromHttpRequest) > > ->map($serializer->serializeToJson(...)) // only executes when the > > Option is Some, not None > > ->map(fn (string $json) =3D> new Response(status: 200, content: $js= on)) > > ->getOrElse(new Response(status: 404)); > > ``` > > Ehm, wouldn't that be the same as a Pipe class that's configured to > stop on null? > > public function getThing($id) { > return new Pipe( > $this->getData(...), > $this->serializeData(...), > $this->mapToResponse(...) > ) > ->stopOnEmpty() > ->from($id) > ->run(); > } > > Wait, are you using map() for arrays or not? Looks like not. > > Olle > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > I might be venting, but, I wish the operators RFC had passed...