Skip to content

Instantly share code, notes, and snippets.

@dfockler
Created September 11, 2015 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfockler/d9e00153ba76736cc79c to your computer and use it in GitHub Desktop.
Save dfockler/d9e00153ba76736cc79c to your computer and use it in GitHub Desktop.
Lambdas
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