Naveen Chawla (2017-07-06T13:51:36.000Z)
Suitable for that would be an "until" function that returns an array with
all elements of the target array until a condition is met (which can then
be followed by a chained call to forEach/forEvery), not "forEach" /
"forEvery" as such. Reason: readability. The counterpart could be an
"after" function which returns an array with all elements after the first
element that satisfies a condition. (Maybe even "untilInclusive"/"from" for
the inclusive versions too).

On 6 July 2017 at 18:21, Sebastian Malton <sebastian at malton.name> wrote:

> Would allowing for each to have the following two properties also help?
>
> 1. Returning a falsy value ends the chain and the next element will not be
> called
> 2. Ability to pass in a call back as parameter 4 and if present will stop
> the next element from being iterated over until the callback is called with
> a truthy value (falsey also ends)
>
>
>
> *From:* naveen.chwl at gmail.com
> *Sent:* July 6, 2017 8:44 AM
> *To:* es-discuss at mozilla.org
> *Subject:* Re: Re: Return value of forEach
>
> In that case, there should be a new function:
>
> "forEvery" (or "forEachAndReturn" or "each" or whatever)
>
> that does exactly the same as "forEach" but returns the array.
>
> This is a much needed feature for those of us that don't want to create a
> new array on each invocation but still have the ability to transform the
> contents of the array (or do some other processing) from within a .sort /
> .map / .filter etc. chain.
>
> Otherwise, in complicated transformations, we have to end the chain,
> perform the forEach separately, and then resume the chain, making the code
> more messy. Sort is an example of a function that already allows mutation
> of the existing array and returns it, so this would be nothing
> extraordinary for ES.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170706/3d98f0d0/attachment-0001.html>
naveen.chwl at gmail.com (2017-07-06T17:11:01.375Z)
-
naveen.chwl at gmail.com (2017-07-06T17:10:36.800Z)
naveen.chwl at gmail.com (2017-07-06T15:00:46.320Z)
Sebastian, suitable for that would be an "until" function that returns an array with
all elements of the target array until a condition is met (which can then
be followed by a chained call to forEach/forEvery), not "forEach" /
"forEvery" as such. Reason: readability. The counterpart could be an
"after" function which returns an array with all elements after the first
element that satisfies a condition. (Maybe even "untilInclusive"/"from" for
the inclusive versions too).