diff options
Diffstat (limited to 'src/either.js')
-rw-r--r-- | src/either.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/either.js b/src/either.js new file mode 100644 index 0000000..75b3c4c --- /dev/null +++ b/src/either.js @@ -0,0 +1,17 @@ +import * as wrapper from "./wrapper.js" + +export const Left = v => left => right => left(v) +export const Right = v => left => right => right(v) + +export const isLeft = either => either(true)(_ => false) +export const isRight = either => either(false)(_ => true) + +export const getLeft = left => left(v => v)() +export const getRight = right => right()(v => v) + +export const show = either => either(v => "Left " + v)(v => "Right " + v) + +export const unit = Right +export const bind = mx => f => mx(Left)(f) + +export const DO = wrapper.DO(unit, bind) |