From 6da602b0a29afcd2aa15725547375a80e30b3983 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 27 Nov 2024 02:12:12 +0100 Subject: initial commit --- src/either.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/either.js (limited to 'src/either.js') 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) -- cgit v1.2.3