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)



Sent: July 6, 2017 8:44 AM
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

Reply via email to