Skip to content

Instantly share code, notes, and snippets.

@danhodge
Created January 18, 2013 14:05
Show Gist options
  • Save danhodge/4564735 to your computer and use it in GitHub Desktop.
Save danhodge/4564735 to your computer and use it in GitHub Desktop.
class Monad
def self.unit(value)
monad = new
monad.define_singleton_method(:bind) { |func, *args| func.call(*([value] + args)) }
monad
end
def lift(name, func, *args)
define_singleton_method(name) { Monad.unit(bind(func, args)) }
self
end
end
identity = Monad.unit("Hello World")
identity.bind(lambda { |arg| puts arg })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment