aboutsummaryrefslogtreecommitdiff
path: root/src/maybe.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/maybe.js
initial commit
Diffstat (limited to 'src/maybe.js')
-rw-r--r--src/maybe.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/maybe.js b/src/maybe.js
new file mode 100644
index 0000000..3d83b20
--- /dev/null
+++ b/src/maybe.js
@@ -0,0 +1,16 @@
+import * as wrapper from "./wrapper.js"
+
+export const Nothing = nothing => just => nothing
+export const Just = v => nothing => just => just(v)
+
+export const isNothing = maybe => maybe(true)(_ => false)
+export const isJust = maybe => maybe(false)(_ => true)
+
+export const getValue = just => just()(v => v)
+
+export const show = maybe => maybe("Nothing")(v => "Just " + v)
+
+export const unit = Just
+export const bind = mx => f => mx(mx)(f)
+
+export const DO = wrapper.DO(unit, bind)