News for hackers. Stuff that matters.
Re:Ruby 3.2.0 Is from Another Dimension by petre on Wednesday January 04, 2023 @08:27AM (#34245265)
> 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.
Re:Ruby 3.2.0 Is from Another Dimension by robertlagrant on Wednesday January 04, 2023 @08:38AM (#34245368)
True, although that seems less readable than the comprehension versions. I might be just biased, though.
Re:Ruby 3.2.0 Is from Another Dimension by zem on Wednesday January 04, 2023 @05:30PM (#34252851)
you can define pretty much everything as a reduce operation though