blob: c72e114c762b6f26de20352c8f5e668e5884afe1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
; LIB
(let just (\[a]
["maybe" "just" a]))
(let nothing (\[]
["maybe" "nothing"]))
(let unsafe-at (\[n seq]
(match seq
[]
(error "unsafe-at out of bounds")
(match n
0
(head seq)
(unsafe-at (- n 1) (tail seq))))))
(let unpack-just (unsafe-at 2))
(let kind (unsafe-at 1))
(let map (\[f m]
(match (kind m)
"just" (just (f (unpack-just m)))
"nothing" (nothing))))
(let and-then (\[f m]
(match (kind m)
"just" (f (unpack-just m))
"nothing" (nothing))))
; TESTING
(let print-line! (\[s]
(print! (concat s "\n"))))
(let m (just 10))
(match (kind m)
"just"
(print-line! (fmt "found just {0}!" [(unpack-just m)]))
"nothing"
(print-line! "found nothing!"))
;; (export [
;; just
;; nothing
;; unpack-just
;; kind
;; map
;; and-then
;; ])
|