Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active June 23, 2017 16:14
Show Gist options
  • Select an option

  • Save dewey92/c10caa9a63096657bac0bf53e214eb42 to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/c10caa9a63096657bac0bf53e214eb42 to your computer and use it in GitHub Desktop.
const Right = value => ({
map: f => Right(f(value)), // Either[E,A].map(fn: A => B): Either[E,B]
bind(f) { return this.map(f).join() }, // Either[E,A].bind(fn: A => Either[E,B]): Either[E,B]
join: () => value,
isRight: () => true,
isLeft: () => false,
cata: (l, r) => () => r(value)
})
const Left = value => ({
map: f => Left(value),
bind: f => Left(value),
join: () => Left(value),
isRight: () => false,
isLeft: () => true,
cata: (l, r) => () => l(value)
})
// Either[Left,Right]
const Either = val => Right(val)
Either.of = val => Either(val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment