|
|
|
|
|
by robertlagrant
1266 days ago
|
|
The Python one looks fine to me, although I am a Pythonish person. It uses what people already know: the for something in somethings syntax of the for loop, and the if syntax. Also it's nice that this works in dictionaries, generators and lists. It also has the same narrative flow of Haskell's list comprehensions, which I think come from set theory: [x^2 | x <- [0..10], x `mod` 5 /= 0]
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.
This works in ruby 2.5.1. Probably works in 1.9 and mruby as well.