From: Kristof Bastiaensen Date: 2004-05-17T23:24:29+09:00 Subject: Re: RCR: More enumerator functionality Hi, On Mon, 17 May 2004 15:55:25 +0200, Robert Klemme wrote: >> >> what's wrong with >> (1..3).select {|x| x[0]==0}.each {|x| p x} >> ? > > If the Enumerable contains a huge number of elements then this version > will burn a lot of memory while in certain cases (e.g. printing) it is > more efficient to be able to handle one element at a time only. > > Well, of course in those cases you could simply do > > (1..3).each {|x| p x if x[0]==0} > > :-) > That's indeed more elegant than with filter and lambdas. The filter method would be only useful for implementing enum_filter, maybe I will exclude it from the RCR. Enum_filter would also behave like select, but it would be more efficient for memory. And you can keep the enumerable around it you need it later (even when the original object has changed it's contents). > Regards > > robert Thanks, Kristof