Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93040 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91267 invoked from network); 3 May 2016 14:08:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2016 14:08:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:37519] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/22-03860-0F0B8275 for ; Tue, 03 May 2016 10:08:49 -0400 Received: by mail-wm0-f49.google.com with SMTP id a17so41588239wme.0 for ; Tue, 03 May 2016 07:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=YZFzJjAYOuiWg9qd0gGqQxjAIq0JeAtMCDMeRpy0Kgw=; b=Aj4t9O/Yy4wIA/Jx/01qGBiQTbPdHy6nIDiB4AnAH9Zux/SLiQve7EBpFGeehNPFy2 Rk/lQri6fWS1jjY9XqmqVlm2VJbUqA4YoctN2fZfTjIyEn4njrXm6cDb2jq5efEgRP/h JksRbQ37PlWL3ziX9flesHm8QBAGJWZkObHgIfuBVk0iMosgSu8SaxRL6zGfbxk0MR24 4N1fCH43ZwupmldpKf2kGahxa/oEhTVp+ndyZBNHIXf2tJewXXfxidt86N2pN4rMbXPC z9GB3+IeHpFZeQ75GJSe50w6qEpvTNIHMpu/ImEBOeQBFXBTSR5+Xu8IQqGYW59inIr8 qwEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=YZFzJjAYOuiWg9qd0gGqQxjAIq0JeAtMCDMeRpy0Kgw=; b=ANDhBIy27SxaO3zxwAWlwhZGjULXkRHOYezSmTH3VJQFGkglsgJO1NftUW7OclpJRy BDehSi6vilFrneY/TR3mOdV6Hu8oR1GJCTjica852EptrBuIW17pABdArGR/3XW5ev5s RdVme7Ebu8bBNUgMapkjU73TbOHHN7WETAfH9IHiiSoCzNuIqDuCQfsfqGa64hk22dDz dvUYBIZ1TztqrkgI2fp5rGz4BCG4b6sqAVc1pnryEmMZg0cxi1gYEfa+6W+SKhZ392GW F+1ZCR9yp8WtAAf9eh7MsyrUzHsD+z0TYNzT4XFEc5oSLqEiKvVr3KNQ/1LYpM3mYiAj Oahw== X-Gm-Message-State: AOPr4FXkfoaj0snn+yA4KXUidrHvPBwSE/OWhrW3RPUf/h9WSoJL/kNhbCvmvO57hiEZaw== X-Received: by 10.194.175.70 with SMTP id by6mr3199106wjc.19.1462284525921; Tue, 03 May 2016 07:08:45 -0700 (PDT) Received: from [192.168.0.76] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id l124sm4692893wmf.11.2016.05.03.07.08.44 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 03 May 2016 07:08:45 -0700 (PDT) To: internals@lists.php.net References: <4fc01507-3d07-2309-a4e4-4cad7325249b@gmail.com> Message-ID: <25232650-0737-865e-09a7-b8e648ed68e0@gmail.com> Date: Tue, 3 May 2016 15:07:01 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Pipe Operator From: rowan.collins@gmail.com (Rowan Collins) Stephen Coakley wrote on 03/05/2016 01:57: > On 04/30/2016 06:14 PM, Rowan Collins wrote: >> The basic pattern would be: >> >> |=> $tempVar; // terminate the chain and capture the value >> // do stuff with $tempVar >> $tempVar // restart the chain >> >> So: >> >> scandir($arg) >> |> array_filter($$, function($x) { return $x !== '.' && $x != >> '..'; }) >> |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; >> }, $$) >> |=> $fileList; >> if ( someCheck($fileList) { >> something(); >> } >> $fileList >> |> getFileArg($$) >> |> array_merge($ret, $$) >> |=> $ret; >> >> If I don't need the condition any more, I can delete lines 4 to 8, and >> I've got back my original chain. > > Could you use a closure instead to accomplish this? (Again yes, Sara > could you clarify if this is permitted?) > > $ret = scandir($arg) > |> array_filter($$, function($x) { return $x !== '.' && $x != > '..'; }) > |> array_map(function ($x) use ($arg) { return $arg . '/' . > $x; }, $$) > |> (function($fileList) { > if (someCheck($fileList)) { > something(); > } > return $fileList; > })($$) > |> getFileArg($$) > |> array_merge($ret, $$); > > Not completely the best, but perhaps there's some sort of an idea here? The disadvantage here is that you're still having to mutate your code to fit the piped style, even if it's just wrapping into the closure. I was aiming for a style that would let me freely mix piped and unpiped code. Meanwhile, I still see having the assignment at the end of the chain as an end in itself - the ability to use the pipe operator as an expression seems like a nightmare waiting to happen to me. As currently proposed, you could write this, which is just horrible: if ( scandir($arg) |> array_filter($$, function($x) { return $x !== '.' && $x != '..'; }) |> count($$) > scandir($arg) |> count($$) ) { ... } Obviously, it's always possible to show horrible abuses of a feature, but I can't think of any sensible place to use a pipe as an expression except in order to either assign it to a variable, or return it from a function. Regards, -- Rowan Collins [IMSoP]