So, I don’t quite get Ruby 1.9 ‘s changes on enumerators, but what I’d like is a lazy filtering/mapping on a collection, so for example how can I create a lazy enumerator that would be the equivalent of this …
(1..100).find_all{|x| x % 2 == 1}.map{|x| x * 2}.find_all{|x| x % 3 == 0}
I tried passing a lambda to #enum_for, but it doesn’t work on my machine.
You can find implementations of lazy_select and lazy_map in this blog. You will just have to extend the Enumerator module by those two methods. Then you should be able to use