Last active
January 4, 2016 03:29
-
-
Save evanrinehart/8562200 to your computer and use it in GitHub Desktop.
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
function just(x){ return {just: x}; } | |
var nothing = {nothing: null}; | |
function maybe(d, f, m){ | |
if('nothing' in m){ | |
return d; | |
} | |
else if('just' in m){ | |
return f(m.just); | |
} | |
else{ | |
throw new Exception("invalid maybe value"); | |
} | |
} | |
function >>=(m, f){ | |
if('nothing' in m){ | |
return nothing; | |
} | |
else if('just' in m){ | |
return f(m.just); | |
} | |
else{ | |
throw new Exception("invalid maybe value"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment