Last active
December 7, 2018 21:27
-
-
Save havenwood/27a5850b99bb35f855b079038664b120 to your computer and use it in GitHub Desktop.
Enumerable#find_map (#ruby irc channel question)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
def find_map | |
return enum_for __method__ unless block_given? | |
each do |item| | |
found = yield item | |
return found if found | |
end | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment