Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93035 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53045 invoked from network); 3 May 2016 02:54:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2016 02:54:03 -0000 Authentication-Results: pb1.pair.com header.from=terry@terah.com.au; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=terry@terah.com.au; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain terah.com.au designates 209.85.213.174 as permitted sender) X-PHP-List-Original-Sender: terry@terah.com.au X-Host-Fingerprint: 209.85.213.174 mail-ig0-f174.google.com Received: from [209.85.213.174] ([209.85.213.174:36863] helo=mail-ig0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0B/9D-03860-7C218275 for ; Mon, 02 May 2016 22:54:00 -0400 Received: by mail-ig0-f174.google.com with SMTP id u10so103541085igr.1 for ; Mon, 02 May 2016 19:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=terah-com-au.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=X3nACNNLygzgDTM4jdhk+TjHVtV+BtSqmob4+S0390E=; b=G+XkuLMv2QSerMALfk9F0pibX+yVL51xKEoab1H3lRHfNQlRb1VAQsYwpzLfy7rLbO su6O8eDaBnKHDx89H6ERkVzjqxQISMpxbXEupBHXHrmUtnpsdirvsY5SgAvHu+M4ok/9 TzaMQCm/OHW99LtqdgH97tAWqiaWRVmAOJQXVBlKTuLkh27Q13MZX9lG49ALnp+0/7cy 953avz2uTPa7xu0xo2IYUTVG6GCjJ24gJ7PNnB4ZjmvO5uih+qHK09K1/XeJ4oHv/7Nl Z7qdbFxEO8yubanl4ivb5Lfo0ktIimE7m0GpPr/wCrf8INnS2G81B8rZDCJL7kEFx0hi XTTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=X3nACNNLygzgDTM4jdhk+TjHVtV+BtSqmob4+S0390E=; b=lFII7mKCKKexkuU0IlY1thYblKREvVNpzmu7VsUbSs1x68Rlt4DdzL2+m6pwH7paCC lND3JAmnr6kWyCIINzWCa61iy87ZsoTba7UJoSB6xEnH8IKfSbU61L335FyYTMCyXdiG bxtNt4BcFEpBfucuMxPXwC0geOCpFaucm24Xy0x8oSsXtySymSbn6ER12y7pBqFNJ1WO 0FxYs02hZvP+Fy1WlIGeTxfBedNhbnAOpOSU/8pIH/vngXVDupGIDrQQPNZETBJ3Wyfp tFaHp3emZs2uYYZTK8UQrhZLYvU/IaJi4JAyy1yVMMJNdVHQyEE4kSFkA1S2gmgW+5HF Z1OA== X-Gm-Message-State: AOPr4FV4o6rQXY5zI3Xn7yH0mujzZHA+lHw3VRFu1JkX77ginZzbduGl0zjEZ0dsip5q2ZOheckTMJg7DSDlCQ== X-Received: by 10.50.102.69 with SMTP id fm5mr23718099igb.70.1462244037145; Mon, 02 May 2016 19:53:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.15.72 with HTTP; Mon, 2 May 2016 19:53:27 -0700 (PDT) X-Originating-IP: [130.102.152.126] In-Reply-To: References: <4fc01507-3d07-2309-a4e4-4cad7325249b@gmail.com> Date: Tue, 3 May 2016 12:53:27 +1000 Message-ID: To: Stephen Coakley Cc: internals Content-Type: multipart/alternative; boundary=047d7b10ca0968d3c10531e738cb Subject: Re: [PHP-DEV] [RFC] Pipe Operator From: terry@terah.com.au (Terry Cullen) --047d7b10ca0968d3c10531e738cb Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 3 May 2016 at 10:57, Stephen Coakley wrote: > On 04/30/2016 06:14 PM, Rowan Collins wrote: > >> On 29/04/2016 20:58, Sara Golemon wrote: >> Let's say I want to add a condition just before getFileArg(); with the >> current version I've got to: >> - go to the beginning of the chain, and assign to something other than >> $ret >> - go to where I want to break the chain, and reintroduce the $ret >> assignment >> - add my check in the gap, using the variable I just added at the >> beginning of the chain >> >> $fileList =3D scandir($arg) >> |> array_filter($$, function($x) { return $x !=3D=3D '.' && $x !=3D= '..'; >> }) >> |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; }, >> $$); >> if ( someCheck($fileList) { >> something(); >> } >> $ret =3D getFileArg($$) >> |> array_merge($ret, $$); >> >> The syntax is fighting me here, making me jump around the code. But if >> assignment was always on the end of the chain, I would only need to make >> changes at the point where I was breaking the chain. The basic pattern >> would be: >> >> |=3D> $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 !=3D=3D '.' && $x !=3D= '..'; >> }) >> |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; }, >> $$) >> |=3D> $fileList; >> if ( someCheck($fileList) { >> something(); >> } >> $fileList >> |> getFileArg($$) >> |> array_merge($ret, $$) >> |=3D> $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 coul= d > you clarify if this is permitted?) > > $ret =3D scandir($arg) > |> array_filter($$, function($x) { return $x !=3D=3D '.' && $x != =3D > '..'; }) > |> 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? > > > -- > Stephen > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > =E2=80=8BDoesn't Nikic's scalar objects (https://github.com/nikic/scalar_ob= jects) more or less achieve the same thing while also cleaning up the std lib? $ret =3D scandir($arg) ->filter(function(){}) ->map(function(){}) ->merge($someOtherArray); Terry Cullen --047d7b10ca0968d3c10531e738cb--