I think the infinite enumerator is very convenient for writing FP style scripts, but I have yet to find a convenient way to build such a structure in Ruby.
I know that I can build it explicitly:
a = Enumerator.new do |y| i = 0 loop do y << i += 1 end end a.next
but it is annoyingly verbose for such a simple structure.
Another approach is to βcrackβ using Float::INFINITY :
b = (1..Float::INFINITY).each b = (1..1.0/0.0).each
These two are probably the least awkward solution I can give. Although I would like to know if there is any other more elegant way to build infinite counters. (By the way, why does Ruby just make inf or infinity as a literal for Float::INFINITY ?)
source share