From: Christopher Dicely Date: 2010-08-28T06:34:55+09:00 Subject: Re: Lazy array On Sun, Aug 1, 2010 at 3:45 PM, Andrew Wagner wrote: > How can I get a lazy array in Ruby? E.g., in Haskell, I can talk about > [1..], which is an infinite list, lazily generated as needed. I can also do > things like "iterate (+2) 0", which applies whatever function I give it to > generate a lazy list. In this case, it would give me all even numbers. > Anyway, I'm sure I can do such things in Ruby, but can't seem to work out > how. The Ruby equivalent of a lazy array is an enumerator. In Ruby 1.9.2, you can get an infinite list of positive integers as: (1..Float::INFINITY).to_enum, For non-negative even integers, you could do: (0..Float::INFINITY).step(2)