DEV Community

Discussion on: 5 Programming Patterns I Like

Collapse
 
johncip profile image
jmc • Edited

Oh yeah, in case you haven't seen it in action, you might be interested to know that a side-effect-free series of map calls can be refactored similar to your #3. map distributes across function composition, so

map(g, map(f, coll)) == map(compose(g, f), coll)

The latter form only walks the collection once, obviously. You can compose the functions manually or borrow compose from a library like Ramda.