Skip to content

Instantly share code, notes, and snippets.

@3v0k4
Last active December 21, 2019 00:06
Show Gist options
  • Select an option

  • Save 3v0k4/0caedc8ddf6a1bc6c30f6ade274124a1 to your computer and use it in GitHub Desktop.

Select an option

Save 3v0k4/0caedc8ddf6a1bc6c30f6ade274124a1 to your computer and use it in GitHub Desktop.
const Right = x =>
({
x,
map: f => Right(f(x)),
chain: f => f(x)
})
const Left = x =>
({
x,
map: _ => Left(x),
chain: _ => Left(x)
})
Right(1).map(x => x + 2) // Right(3)
Right(1).chain(x => x + 2) // 3
Left(1).map(x => x + 2) // Left(1)
Left(1).chain(x => x + 2) // Left(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment