Created
April 24, 2018 17:32
-
-
Save Rafe/9edb247feb8cb45c46e8d3f82964bee3 to your computer and use it in GitHub Desktop.
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
class Maybe | |
def initialize(val) | |
@val = val | |
end | |
def fmap | |
return self if @val.nil? | |
self.class.new(yield @val) | |
end | |
def inspect | |
return 'Nothing' if @val.nil? | |
"Just #{@val.inspect}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment