blob: fe0b418d18a18a065a64372c51136495f8eea525 (
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
50
51
|
; LIB
(let just (\[a]
["maybe" "just" a]))
(let nothing (\[]
["maybe" "nothing"]))
(let unsafe-at (\[n seq]
(match seq
[]
(fatal "unsafe-at out of bounds")
otherwise
(match n
0
(head seq)
otherwise
(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!"))
(let exports [
just
nothing
unpack-just
kind
map
and-then
])
|