Created
August 20, 2020 00:57
-
-
Save acjr1910/144ca5f972089f86fa14c1cfa02e022d to your computer and use it in GitHub Desktop.
either-monad.js
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 => | |
({ | |
chain: f => f(x), | |
map: f => Right(f(x)), | |
fold: (f, g) => g(x), | |
toString: () => `Right(${x})` | |
}) | |
const Left = x => | |
({ | |
chain: f => Left(x), | |
map: f => Left(x), | |
fold: (f, g) => f(x), | |
toString: () => `Left(${x})` | |
}) | |
const fromNullable = x => | |
x != null ? Right(x) : Left(null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment