Hacker News new | ask | show | jobs
by petre 1266 days ago
> As for your Ruby examples: I think you could argue that the filter_map version is very readable, but not necessarily more so, but the select one looks pretty painful.

The select does two passes, which makes it quite inefficient. One does not even need filter_map, since the example is essentially a reduce operation.

   res = (1..10).reduce([]) { |a, x| x != 5 ? a.push(x**2) : a }
This works in ruby 2.5.1. Probably works in 1.9 and mruby as well.
2 comments

True, although that seems less readable than the comprehension versions. I might be just biased, though.
you can define pretty much everything as a reduce operation though