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
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 one could break-to-label to a label of a lexically

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
On Mon, Feb 23, 2015 at 10:09 AM, Andreas Rossberg rossb...@google.com wrote: On 23 February 2015 at 16:22, Mark S. Miller erig...@google.com 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

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
On 23 February 2015 at 16:22, Mark S. Miller erig...@google.com 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

RE: short-circuiting Array.prototype.reduce

2015-02-22 Thread Domenic Denicola
My initial feedback is that this needs a lot more why in comparison to the how. The only inkling of why this might be useful is an unsourced assertion that it's done in Clojure, for unknown reasons. The example code isn't very compelling either; something more real-world would be good there.

Re: short-circuiting Array.prototype.reduce

2015-02-22 Thread Dmitry Soshnikov
On Sun, Feb 22, 2015 at 10:11 PM, Domenic Denicola d...@domenic.me wrote: My initial feedback is that this needs a lot more why in comparison to the how. The technical reason for this I guess, is that JS doesn't have TCP blocks, that would allow you to stop iteration, and exit the `reduce`