From: Robert Dober Date: 2006-04-13T22:24:28+09:00 Subject: Re: map_if, collect_if ??? ------=_Part_17703_19403053.1144934665512 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 4/13/06, Kroeger, Simon (ext) wrote: > > > > module Enumerable > > > def map_if( &block ) > > > find_all(&block).map(&block) > > > end > > > end > > [...] > > I will file away the find_all {}.map {} idiom for future use > > [...] > > I would change that to: > > map(&block).select{|e|e} > > there can be surprising side effects if the user doesn't > expect the block to be called twice for each element. > > cheers > > Simon Good point. This block twice thing felt elegant and wrong in the same place. I thaught that perfomance should not be a design issue, but Bruce's point was well taken. The side effect thing might not strike often, but if it strikes, boy I woul= d not want to debug that baby. Nice discussion. Robert -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_17703_19403053.1144934665512--