Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93036 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59209 invoked from network); 3 May 2016 04:49:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2016 04:49:29 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.215.51 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.215.51 mail-lf0-f51.google.com Received: from [209.85.215.51] ([209.85.215.51:36618] helo=mail-lf0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/3E-03860-7DD28275 for ; Tue, 03 May 2016 00:49:28 -0400 Received: by mail-lf0-f51.google.com with SMTP id u64so8720666lff.3 for ; Mon, 02 May 2016 21:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=dK49TiDaS+ljC5D0Y/CU7CZAVYI3noE6HWDDfnhRNXw=; b=GUyLjQ+CJgZouTtIapWzwYoVRR9xPtySyvMmLlWFT36GoT9YZfBhaFufSkCgBnC9+4 WBtdn/3BD1UeAw0RKkFKHv+438R+ySQ67FR9Odgcr5gd+hXFiaL8mwWTlFZcwSVSUNTa vC+DVcpjH+mayF/ALG9udqLP9PvOCvx137VCuJPr6glQcCUxi9f2vVZjLuzN63iRmzwH KqSM3TAJgnMEavqLMmq8KZwgZbQeZSYBfVyrk0oIKHBVe7s8SfVLOVoqWcWhiNX76HqG 0f4QFqeiWK7iOZ3lam5vVLO0JJpK+evcpdg8usO7koJpLo9DusGIJM1PoWo7efbtjgBL aN5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=dK49TiDaS+ljC5D0Y/CU7CZAVYI3noE6HWDDfnhRNXw=; b=jLerAtqQ5wA+LyjxEJr3Ih+FrMdb9Dbs7zRjz4uiAO4xAUhEKicK6r7MEbVAprXPkI eE/hbo2dpzhqrlXomsx/5kbg3IWrxB7noU+vdt9cLUTXP+I5nhltEeW/juj6vILAHSfv /IDbF8Jeju/Pq4GHVQDhgCb8Qd2T+5WXHtK8W0/sXxXL5boRN0OBXVFO6BizVpKLJLHp h5fGo5ojpLEERwUB/amJ1o+fGlAjrUIyfxocQr7WMn3UeLIpVRQ/mKK6eQIad+DNi4fr qkDlSFSLh9q7Qd2i9bDmAFti8FhmHVWj1R/5uFiV+WRAbxApA59MTEbnFwwHlN+/5HqG s12w== X-Gm-Message-State: AOPr4FWRYb/V74YPqHp4Rq1bPjEKdvcFTYmEde9un7NszQHB2lRbHtx0Lo0wlCNJrLpddFylbE+zJUaIfDYKpg== MIME-Version: 1.0 X-Received: by 10.112.129.162 with SMTP id nx2mr164557lbb.43.1462250965195; Mon, 02 May 2016 21:49:25 -0700 (PDT) Sender: php@golemon.com Received: by 10.112.19.72 with HTTP; Mon, 2 May 2016 21:49:25 -0700 (PDT) X-Originating-IP: [107.198.91.68] In-Reply-To: References: <4fc01507-3d07-2309-a4e4-4cad7325249b@gmail.com> Date: Mon, 2 May 2016 21:49:25 -0700 X-Google-Sender-Auth: QfJDYHZ14Rc_ZyWBrxHoq3Ryt1o Message-ID: To: Stephen Coakley Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Pipe Operator From: pollita@php.net (Sara Golemon) On Mon, May 2, 2016 at 5:57 PM, Stephen Coakley wrote: > 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, $$); > You could, but IMO you lose a lot of the elegance if you go that route. This syntax works best when you have a series of functions which /don't/ have failure cases (and many many functions don't), or who fail via exceptions. Using current syntax, the above would look like: $ret = array_merge($ret, getFileArg(function($fileList) { if (someCheck($fileList)) { something(); } return $fileList; })(array_map(function($x) use ($arg) { return $arg . '/' . $x; }, array_filter(scandir($arg), function($x) { return $x !== '.' && $x !== '..'; })) ))); It's way more readable in the pipe syntax version, but it's overloading a single statement in both places. -Sara