Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88617 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41496 invoked from network); 1 Oct 2015 18:06:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Oct 2015 18:06:03 -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 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:34321] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/F2-26330-A067D065 for ; Thu, 01 Oct 2015 14:06:02 -0400 Received: by wicfx3 with SMTP id fx3so2249110wic.1 for ; Thu, 01 Oct 2015 11:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=xNWOj95neH3rklxo2lPDZJI/9WM9X/huxpCnB4gUIEI=; b=XrVl0LnzVPHdb+er+IJaoZZT5s/3FMuvBpRuRhON3Fw3RCshplnlQfUM7Ao1GZXBqm h5uITRXpo/n9s77lvrUIOnlHHOpTGlWqQZMoW2u9mUN/00EQKCDOcz4BXETwQxVwjK48 ZtHSLUpRrxAKreDkHl8+u26lcwtLM5rC8zGN9pGs75QJda+ElZo7L9D89fAdV6tGusmQ biUNW/1hNhvO5prlwvD7ME/Brs46sxBAZ5c3F8BTiKn6b8KtHC4yT0oBjzGhjMvYF+wz NjA6srQMAOuFtFlnBDelcra7sTupXo2+gGWzsfc+1Fgu9yZEvhm25cpR3IWHyXg/LgNo gyDQ== X-Received: by 10.194.115.199 with SMTP id jq7mr13097838wjb.82.1443722760050; Thu, 01 Oct 2015 11:06:00 -0700 (PDT) Received: from [192.168.0.161] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id pu6sm7302353wjc.34.2015.10.01.11.05.59 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 01 Oct 2015 11:05:59 -0700 (PDT) To: Levi Morrison References: <5606D0EB.3060106@gmail.com> <560D0F94.8060009@gmail.com> <560D282F.6060202@gmail.com> <560D638E.5020706@gmail.com> Cc: "internals@lists.php.net" Message-ID: <560D7601.7080100@gmail.com> Date: Thu, 1 Oct 2015 19:05:53 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.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] Arrow function expressions in PHP From: rowan.collins@gmail.com (Rowan Collins) Levi Morrison wrote on 01/10/2015 18:38: > Chain works is because the functions passed to it accept iterables as > their only parameter and return either an another iterable or a > reducing function (in this example sum is the reducer). This is why > the functions are returning closures that accept only one parameter. OK, that makes sense of one level of indirection. It doesn't however seem to justify the nesting in reduce() If I understand correctly, your library obliges me to write this: $algorithm = chain( map(function($x) => $x * 2), reduce(0)(function($acc, $val) => $acc + $val) ); $algorithm([1,2,3]); But that seems to have no advantage over this: $algorithm = chain( map(function($x) => $x * 2), reduce(0, function($acc, $val) => $acc + $val) ); $algorithm([1,2,3]); Which would make the body of reduce significantly simpler, because it's just one named function accepting a closure, and returning a closure, with no further nesting. The function chaining only appears to be useful if the closure returned by reduce(0) is to be passed or applied in some other way, and I can't think of when that would be required. Regards, -- Rowan Collins [IMSoP]