From: "David J. Hamilton" Date: 2011-01-12T02:03:20+09:00 Subject: Re: Best way for Array#find+transform ? Excerpts from botp's message of Tue Jan 11 08:02:45 -0800 2011: > On Tue, Jan 11, 2011 at 2:49 PM, David J. Hamilton wrote: > > ...wanted to avoid having to write the transformation twice.  See his previous > > example earlier in this thread where he uses find to get the value, and then has > > to transform (again) the result. > > ah, ok (slaps my dummy head after whole thread :-) > > in that case, i'd still prefer something like > > paths.map{|path| File.join(path,filename)}.find{|path| File.exists?(path)} > #=> "/opt/jruby" Yes, Anurag suggested transforming and then selecting (as you have done, above). Jonas's complaint here is that much of the transformation is unnecessary, specifically every transformation that occurs after the value to be searched for. Whether this is an inelegance is a matter of taste. Personally I find code that does more than it needs to a little confusing, or at least inelegant. As a matter of performance, it may not matter much in this case, but in general it is good to know the semantics of break for cases where the transformation itself is expensive, or if the Enumerable is very large (say, infinite). -- med vänlig hälsning David J. Hamilton