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/maybe.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/maybe.js (limited to 'src/maybe.js') 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) -- cgit v1.2.3