Last active
December 21, 2019 00:25
-
-
Save 3v0k4/69eed99938a569030ead4cb3f77cf0df to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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