From: Tanaka Akira Date: 2013-09-01T13:00:51+09:00 Subject: [ruby-core:56952] Re: [ruby-trunk - Feature #8840] Yielder#state 2013/9/1 marcandre (Marc-Andre Lafortune) : > > Your example will fail if iterated a second time. > It will also not work correctly when using `rewind` and `next`. Check #7696. How about adding a method to wrap an enumerator to add a state? % ruby -e ' class Enumerator def with_state(init) Enumerator.new {|y| state = init.dup self.each {|v| y.yield [state, v] } } end end class Enumerator::Lazy def drop2(n) e = with_state([n]) Enumerator.new {|y| e.each {|remain, v| if remain[0] == 0 y.yield v else remain[0] -= 1 end } } end end e = (1..42).lazy p e.drop2(40).to_a p e.drop2(40).to_a ' [41, 42] [41, 42] -- Tanaka Akira