DEV Community

Discussion on: Stop returning Null!

Collapse
 
lysofdev profile image
Esteban Hernández

I'm definitely for Generic Wrappers and these can be easily implemented with the above list strategies.

As for forEach(...).forEach(...), that will actually fail since forEach(...) is a consumer function; it doesn't return anything. Instead use map() which is the same as forEach() but it returns a value. I personally like to do stack method chains like so:

items
    .map(...)
    .filter(...)
    .map(...)
    .forEach(...);

That style blends well with list method chains, Promise chains and Streams.

I like the if (counter) style but this isn't going to work in every language and my employer doesn't allow it in our JS code. We have to always use the double check unfortunately.