From: mortee Date: 2007-10-26T06:58:28+09:00 Subject: Re: Intervals in Ruby ara.t.howard wrote: > yes. the most obvious one is needing adjacent entries and/or > self-modification. something along the lines of > > pixels.size.times do |i| > pixel = pixels[i] > left = pixels[i - 1] > right = pixels[i + 1] > > if left.nil? and condition(right) or > condition(left) and condition(right) or > condition(left) and right.nil? > > pixel = transformation left, pixel, right > end > end What about #each_with_index for this case? Using pixels.size.times and accessing each element by the yielded integer indexes explicitely assumes that the index space is continuous - however, the same algorithm using #each_with_index would only assume that each item yielded by it has two adjacent neighbors. > min = [a.size, b.size].min > > min.times do |i| > something_with a[i] and b[i] > end > > which is to say iterating datasets in parallel. > > yes there is zip - fantastic if you are into duplicating both datasets > in memory *and* are iterating over n=2 data structures but otherwise > useless. Hmmm, are you sure that zip duplicates all the involved arrays even if passed a block? mortee