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 <[email protected]> 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:* [email protected] > *Sent:* July 6, 2017 8:44 AM > *To:* [email protected] > *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. >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

