This is the essence of what I'm trying to do but the 'break' doesn't feed right:
needle = nil
haystacks.each do |haystack|
needle = haystack.look_for_needle()
break if needle
end
This is shorter, but it will iterate over every haystack (without looking at least) even though it doesn't need to:
needle = nil
haystacks.each do |haystack|
needle ||= haystack.look_for_needle()
end
This is a one-liner but (I believe) it is not lazy and so it does unnecessary work:
needle = hackstacks.map{|h| h.look_for_needle()}.detect{|x| !x.nil?}
I feel like there should be a one liner, but I'm not sure it would be:
needle = hackstacks.some_find_each_first_detect_lazy_map_thingee {|h| h.look_for_needle()}
haystacks.detect(&:look_for_needle).look_for_needle
.detect
will return the first haystack with a needle and the secondary call tolook_for_needle
will return the Needle (assumption). Not sure how intensivelook_for_needle
is though. – Relique