Re: short-circuiting Array.prototype.reduce

2015-03-27 Thread Jason Orendorff
On Thu, Mar 26, 2015 at 8:22 PM, Kyle Simpson get...@gmail.com wrote: outer = outer.filter(function filterer(inner){ return inner.reduce(function reducer(prev,current){ if (prev === false || prev === current) return false; return current; }); }); I think you could write that

Re: short-circuiting Array.prototype.reduce

2015-03-27 Thread Kyle Simpson
I think you could write that like this: outer = outer.filter(arr = !arr.some((e, i) = i 0 arr[i-1] === e)); Yes, you are of course correct. What I was doing in the originally cited code was illustrating using how `reduce(..)` by its nature supports the adjacency check,

Re: short-circuiting Array.prototype.reduce

2015-03-26 Thread Kyle Simpson
Um, that's not exactly what reduction is meant for. There's lots of different ways `reduce(..)` gets used in the wild; I can list several entirely distinct but common idioms right off the top of my head. Just because it's not the original intent doesn't mean it's invalid to do so. To the

Re: short-circuiting Array.prototype.reduce

2015-03-26 Thread Bergi
Kyle Simpson schrieb: Since `reduce(..)` conveniently can compare two adjacent elements if you always return the current value, I decided to model the inner check as a `reduce(..)` that reduces from the original array value to either a `false` or a truthy value (the last element of the inner

Re: short-circuiting Array.prototype.reduce

2015-03-26 Thread Kyle Simpson
The example code isn't very compelling either; something more real-world would be good I recently ran across a usage of `reduce(..)` that could have benefitted from an early return. Figured I'd just drop it here for posterity sake, in case anything ever comes of this idea. I had an array of

Re: short-circuiting Array.prototype.reduce

2015-02-24 Thread Lee Byron
erig...@google.commailto:erig...@google.com Cc: es-discuss@mozilla.orgmailto:es-discuss@mozilla.org es-discuss@mozilla.orgmailto:es-discuss@mozilla.org Subject: Re: short-circuiting Array.prototype.reduce Mark S. Miller wrote: My other suspicion: The previous failure of this proposal was before many

Re: short-circuiting Array.prototype.reduce

2015-02-23 Thread Mark S. Miller
compelling either; something more real-world would be good there. -- From: Lee Byron leeby...@fb.com Sent: ‎2015-‎02-‎23 00:58 To: es-discuss@mozilla.org Subject: short-circuiting Array.prototype.reduce Hey all, I’d like to propose an addition to ES7 to add @@reduced

Re: short-circuiting Array.prototype.reduce

2015-02-23 Thread Allen Wirfs-Brock
On Feb 23, 2015, at 7:22 AM, Mark S. Miller wrote: We still an an option open to us, that would merely compatibly remove a restriction from the language rather than add a feature: Allow labels to remain visible across function boundaries, or at least across arrow function boundaries. Then

Re: short-circuiting Array.prototype.reduce

2015-02-23 Thread Dmitry Soshnikov
very compelling either; something more real-world would be good there. -- From: Lee Byron leeby...@fb.com Sent: ‎2015-‎02-‎23 00:58 To: es-discuss@mozilla.org Subject: short-circuiting Array.prototype.reduce Hey all, I’d like to propose an addition to ES7

Re: short-circuiting Array.prototype.reduce

2015-02-23 Thread Brendan Eich
Mark S. Miller wrote: My other suspicion: The previous failure of this proposal was before many people had much hands on experience using higher order functions in JS as a normal alternative to control structures. Now that we all have, the need for a non-local escape may be more visceral.

Re: short-circuiting Array.prototype.reduce

2015-02-23 Thread Andreas Rossberg
code isn't very compelling either; something more real-world would be good there. -- From: Lee Byron leeby...@fb.com Sent: ‎2015-‎02-‎23 00:58 To: es-discuss@mozilla.org Subject: short-circuiting Array.prototype.reduce Hey all, I’d like to propose an addition

RE: short-circuiting Array.prototype.reduce

2015-02-22 Thread Domenic Denicola
there. From: Lee Byronmailto:leeby...@fb.com Sent: ‎2015-‎02-‎23 00:58 To: es-discuss@mozilla.orgmailto:es-discuss@mozilla.org Subject: short-circuiting Array.prototype.reduce Hey all, I’d like to propose an addition to ES7 to add @@reduced as a way to short-circuit from

short-circuiting Array.prototype.reduce

2015-02-22 Thread Lee Byron
Hey all, I’d like to propose an addition to ES7 to add @@reduced as a way to short-circuit from Array.prototype.reduce. I’ve written up a polyfill and explanation here: https://github.com/leebyron/ecma-reduced I would love your feedback on this. Lee

Re: short-circuiting Array.prototype.reduce

2015-02-22 Thread Dmitry Soshnikov
, for unknown reasons. The example code isn't very compelling either; something more real-world would be good there. -- From: Lee Byron leeby...@fb.com Sent: ‎2015-‎02-‎23 00:58 To: es-discuss@mozilla.org Subject: short-circuiting Array.prototype.reduce Hey all, I’d like