From: Christopher Dicely Date: 2010-08-28T14:43:03+09:00 Subject: Re: how about Array#collect_until On Fri, Aug 27, 2010 at 9:40 PM, timr wrote: > The other tests may help clarify the expected behavior. In each case > the method should result in a collection that DOES NOT INCLUDE A > RESULT FOR EVERY ITEM in the original set since the condition is met > part way through and break is executed. Therefore, it provides the > most a collection of calculations upto and including the solution when > an end condition was met. Okay.. I misunderstood the intent. So you can't use the Enumerable#through method I proposed upthread quite as simply, because you have to reverse the order of the filtering and transforming operations, and the existing transforming operation for enumerables (Enumerable#map) produces an array, not an Enumerator, and Kernel#enum_for won't pass a block to map (or any other method) to create an Enumerator that uses the block. But its easy to create a general-purpose map-like enumerator method. module Enumerable def transform Enumerator.new do |yielder| self.each { |val| yielder << yield(val) } end end end Then you can just chain this Enumerable#transform in front of the Enumerable#through I proposed upthread,