Skip to content

Instantly share code, notes, and snippets.

@collardeau
Last active April 8, 2018 19:10
Show Gist options
  • Save collardeau/941204e4d13c04b73f97 to your computer and use it in GitHub Desktop.
Save collardeau/941204e4d13c04b73f97 to your computer and use it in GitHub Desktop.
const Maybe = val => ({
val,
fmap(f) {
if(this.val === null) return Maybe(null);
return Maybe(f(this.val));
}
});
// lets create some containers with our Maybe factory
let user = Maybe("Slacker George McFly");
let noUser = Maybe(null);
console.log(user.val); // "Slacker George McFly"
console.log(noUser.val); // null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment