From: Roger Pack Date: 2009-11-14T03:45:00+09:00 Subject: Re: RCR enumerable extra into core >This reminds me of the early 1.9.0 thing, where you could do: > > array = [1,2,3,4] > enum = array.enum_for(:map, &lambda {|x| x * x }) > > enum.next # 1 > enum.next # 4 Appears somewhat possible... class Enumerator def filter(&blk) self.class.new do |y| each do |*input| out = blk.call(*input) y << out # or y << out if out end end end end >> array = [1,2,3,4] >> enum = array.enum_for(:map).filter {|x| x * x } >> enum.next => 1 >> enum.next => 4 >> enum.select {|x| x > 1 } # [4, 9, 16] => [4, 9, 16] [Thanks to Brian Candler for the snippet--though perhaps it could be improved...] This should be the default, though--I don't know why blocks are ignored currently... -r http://www.ruby-forum.com/topic/169844#new -- Posted via http://www.ruby-forum.com/.