Last active
April 8, 2018 19:10
-
-
Save collardeau/941204e4d13c04b73f97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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