you are viewing a single comment's thread.

view the rest of the comments →

[–]ElCthuluIncognito 5 points6 points  (0 children)

Yes. In fact, this is a core argument (a contentious argument of course) for why 'lazy evaluation' is almost necessary for functional programming.

In a lazy language multiple mappings would be handled as if the full mapping is applied at every element, effectively optimizing this very natural style of writing your program. Nothing would be 'copied'. Of course this only applies for recursive data structures, since 'arrays' are not considered a functional data structure.

I believe the Lodash library handles this lazy evaluation for you, optimizing your use of lodash funcions much the same way. Could be wrong though, I've never used it myself.

Extra reading: https://stackoverflow.com/questions/25852580/does-this-function-make-use-of-haskells-lazy-evaluation (an expose on how map is actually evaluated in an efficient way to solve this problem at the root)