aboutsummaryrefslogtreecommitdiff
path: root/src/either.js
diff options
context:
space:
mode:
authorMarvin Borner2024-11-27 02:12:12 +0100
committerMarvin Borner2024-11-27 02:27:48 +0100
commit6da602b0a29afcd2aa15725547375a80e30b3983 (patch)
treebb268dc7935696c2687c4ec151c2e0108536fa6f /src/either.js
initial commit
Diffstat (limited to 'src/either.js')
-rw-r--r--src/either.js17
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)