Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active June 23, 2017 15:49
Show Gist options
  • Save dewey92/eedee1a86e4cc502ae0bd4980e7f927c to your computer and use it in GitHub Desktop.
Save dewey92/eedee1a86e4cc502ae0bd4980e7f927c to your computer and use it in GitHub Desktop.
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