Last active
June 23, 2017 15:49
-
-
Save dewey92/eedee1a86e4cc502ae0bd4980e7f927c 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
const Just = value => ({ | |
map: f => Just(f(value)), | |
bind(f) { return this.map(f).join() }, | |
join: () => value, | |
isJust: () => true, | |
isNothing: () => false, | |
orJust: _ => value | |
}) | |
const Nothing = () => ({ | |
map: f => Nothing(), | |
bind: f => Nothing(), | |
join: () => Nothing(), | |
isJust: () => false, | |
isNothing: () => true, | |
orJust: value => value | |
}) | |
// Maybe[Nothing,Just] | |
const Maybe = val => { | |
if (!val) return Nothing() | |
return Just(val) | |
} | |
Maybe.of = val => Maybe(val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment