From: Brian Candler Date: 2008-11-04T00:01:51+09:00 Subject: Re: Iterator objects and lazy evaluation And here's a wrapper for this pattern: class Enumerator def filter(&blk) self.class.new do |y| each do |*input| blk.call(y, *input) end end end end a = (1..1_000_000_000).to_enum a.filter { |out,inp| out << inp if inp % 2 == 0 }. filter { |out,inp| out << inp+100 }. with_index.each { |inp,c| puts inp; break if c > 10 } $ ruby19 -v ruby 1.9.1 (2008-10-28 revision 19983) [i686-linux] $ ruby19 filter.rb 102 104 106 108 110 112 114 116 118 120 122 124 $ -- Posted via http://www.ruby-forum.com/.