From: Kristof Bastiaensen Date: 2004-06-18T20:58:33+09:00 Subject: Re: [RCR] More enumerator functionality On Fri, 18 Jun 2004 01:54:19 +0900, Michael Neumann wrote: > On Fri, Jun 18, 2004 at 12:03:44AM +0900, Kristof Bastiaensen wrote: >> Hi everybody, >> >> I have finally posted my RCR for more enumerator >> functionality. >> >> Find more about it here: >> http://rcrchive.net/rcr/RCR/RCR262 > > Can you give some more examples, where and how enum_if could be useful? > > Regards, > > Michael Well, enum_if is useful in at least two cases (as I wrote in the analysis). It could be useful as a replacement for Enumerable#select that may be more efficient in some cases, (when dealing with a large amount of data). For example: large_dataset.enum_if { |d| sometest(d) }.collect do |d| end It could also be useful to have a specialized enumerator that will reflect any changes made to the original object: data = ["a", 6, 9, "foo", -19, "fuga", -19, "bach"] ints = data.enum_if { |i| i.is_a? Numeric } ints.to_a => [6, 9, -19, -19] data += ["Bear", 20, 3] ints.to_a => [6, 9, -19, -19, 20, 3] (I have added these examples to the RCR) Cheers, Kristof