4 ms·
Some developers are taking a really "creative" interpretation of the lessons of functional programming. I am currently dealing with a codebase (CoffeeScript) fu
by sedachv 11y ago
Some developers are taking a really "creative" interpretation of the lessons of functional programming. I am currently dealing with a codebase (CoffeeScript) full of:
_.reduce some_array, (result_array, object) ->
...
result_array.push xyz
...
return result_array
, []
- 15155 11y agoIn a lot of languages, stdlibs, what have you, map is implemented in terms of a reduce like this. In a non-lazy language, this kind of a reduce is usually necessary when you want to omit an item efficiently from the resultant array - map does not offer a way to do this.
- sedachv 11y agoDid you miss the explicit side-effects in the code above? This isn't like a map/filter in terms of fold, it is a very stupid way of writing a 'for' loop.