Skip to content

Instantly share code, notes, and snippets.

@pwim
Created May 28, 2012
Embed
What would you like to do?
map + find
# Is there already a pattern for doing this?
def map_find(enumerable)
enumerable.each do |e|
t = yield(e)
return t if t
end
nil
end
# equivalent to the following but with one less function call
t = enumerable.find {|e| foo(e)}
foo(t) if t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment