Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Last active August 29, 2015 14:24
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 guilleiguaran/8b7736cc3531deb5799a to your computer and use it in GitHub Desktop.
Save guilleiguaran/8b7736cc3531deb5799a to your computer and use it in GitHub Desktop.
Array Monad
class Array
def self.unit(value)
[value]
end
def bind(&block)
flat_map(&block)
end
end
@guilleiguaran
Copy link
Author

Example

generation = lambda{|x| Array.unit(x*3)}
[["bunny"]].pass(&generation)
[["bunny"]].pass(&generation).pass(&generation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment