Last active
December 21, 2019 00:06
-
-
Save 3v0k4/0caedc8ddf6a1bc6c30f6ade274124a1 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)), | |
| 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