-
-
Save dfockler/d9e00153ba76736cc79c to your computer and use it in GitHub Desktop.
Lambdas
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 Wrap | |
attr_accessor :value | |
def initialize(value) | |
@value = value | |
end | |
def monad(lamby) | |
Wrap.new(lamby.call(@value)) | |
end | |
end | |
add2 = -> x { x + 2 } | |
sub1 = -> x { x - 1 } | |
puts Wrap.new(5).monad(add2).monad(sub1).value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment