aboutsummaryrefslogtreecommitdiffstats
path: root/examples/maybe.lisp
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-09-26 16:29:32 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-05 14:21:53 +0200
commitf8578936553468785ff1c70fb7f4b0efebfbf55d (patch)
treea726d8d206cd58591ec05895fce5f513a2c6a764 /examples/maybe.lisp
parent367cefd18ba6c96c9753e69a19db84ce50f34abf (diff)
Add maybe concept
Diffstat (limited to 'examples/maybe.lisp')
-rw-r--r--examples/maybe.lisp28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/maybe.lisp b/examples/maybe.lisp
new file mode 100644
index 0000000..ce2cd03
--- /dev/null
+++ b/examples/maybe.lisp
@@ -0,0 +1,28 @@
+; LIB
+
+(let just (\[a]
+ ["maybe" "just" a]))
+(let nothing (\[]
+ ["maybe" "nothing"]))
+
+(let at (\[n seq]
+ (match seq
+ [] (nothing)
+ (match n
+ 0 (head seq)
+ (at (- n 1) (tail seq))))))
+
+(let from-just (at 2))
+(let kind (at 1))
+
+(let map (\[f m]
+ (match (kind m)
+ "just" (just (f (from-just m)))
+ "nothing")))
+
+; TESTING
+
+(let m (just 10))
+(match (kind m)
+ "just" (from-just m)
+ "nothing" "nothing")