From: Martin DeMello Date: 2004-06-03T03:18:39+09:00 Subject: Re: [ann] bidirectional iterator 0.8 Simon Strandgaard wrote: # > # example 2. multiway each > # > require 'iterator' > data_a = %w(a b c d) > data_b = (0..3) > ia = Iterator::Continuation.new(data_a, :each) > ib = Iterator::Continuation.new(data_b, :each) > result = [] > while ia.has_next? and ib.has_next? > result << ia.current > result << ib.current > ia.next > ib.next > end > ia.close > ib.close > p result # ["a", 0, "b", 1, "c", 2, "d", 3] This suggests "higher order" iterators composed of parallel and serial combinations of other iterators. ic = Iterator::Parallel(ia, ib) # or even ic = ia | ib while ic.has_next? a, b = ic.current result << "#{a} -> #{b}" end ic.close martin