Created
October 20, 2013 19:06
-
-
Save obfusk/7073835 to your computer and use it in GitHub Desktop.
obfusk.coffee - reduce + mbind
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
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