Skip to content

Instantly share code, notes, and snippets.

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

  • Save 3v0k4/69eed99938a569030ead4cb3f77cf0df to your computer and use it in GitHub Desktop.

Select an option

Save 3v0k4/69eed99938a569030ead4cb3f77cf0df to your computer and use it in GitHub Desktop.
const Right = x =>
({
x,
map: f => Right(f(x)),
inspect: _ => `Right(${x})`,
isLeft: _ => false,
chain: f => f(x),
})
const Left = x =>
({
x,
map: f => Left(x),
inspect: _ => `Left(${x})`,
isLeft: _ => true,
chain: f => Left(x)
})
const tryCatch = f => {
try {
return Right(f())
} catch (e) {
return Left('could not parse')
}
}
const fromNullable = (error, a) => (a === undefined || a === null) ? Left(error) : Right(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment