So I came across this problem.
I have an array of N elements. I'd like to run every element against a function.
so I would go:
Now I want to filter some of them and call another function on the rest of them.
.forEach(item=>process(item) .filter( somelogic ) .forEach( item=>postProcessSome(item) );
But that's not valid code. forEach returns undefined so I can't call filter. I can use map instead of forEach but that way I can't use one liners.
What's an elegant way to do this? For example in Java I could use .peek that acts like a foreach but returns the value.
Thanks for help.