Skip to content

Instantly share code, notes, and snippets.

@evanrinehart
Last active January 4, 2016 03:29
Show Gist options
  • Save evanrinehart/8562200 to your computer and use it in GitHub Desktop.
Save evanrinehart/8562200 to your computer and use it in GitHub Desktop.
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