Skip to content

Instantly share code, notes, and snippets.

@obfusk
Created October 20, 2013 19:06
Show Gist options
  • Save obfusk/7073835 to your computer and use it in GitHub Desktop.
Save obfusk/7073835 to your computer and use it in GitHub Desktop.
obfusk.coffee - reduce + mbind
O = require 'obfusk'; U = require 'underscore'
f = (x) -> O.Just x + 1
g = (x) -> O.Just x * 42
h = (x) -> O.Nothing()
x = U.reduce([f,g], O.mbind, O.Just(2))
y = U.reduce([f,h,g], O.mbind, O.Just(2))
console.log O.match(x, Nothing: (-> 'too bad'), Just: ((x) -> "#{x.value}!!!"))
console.log O.match(y, Nothing: (-> 'too bad'), Just: ((x) -> "#{x.value}!!!"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment