summary refs log tree commit diff
path: root/lib/either.test.fnl
blob: fc819dc15fe9c3404cd1aecebb18a297a5d92878 (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
(local {: pprint} (require :lib.tableprint))

(let [{
       : Either
       : Left
       : Right
       } (require :lib.either)]

  ;; either
  ;(print "Either Inspection")
  ;(pprint Either)

  ;; you can set and get values
  (let [ v :poop x (Either:new v)]
    (assert (= v x.value) (.. "The value is " v)))

  (let [r (Right:new "rain")
        map (r:map #(.. "b" $1))
        expected :brain
        actual (. map :value)
        ]
    (assert (= expected actual) "You can map a Right value"))

  (let [l (Left:new "rain")
        map (l:map #(.. "b" $1))
        expected :rain
        actual (. map :value)
        ]
    (assert (= expected actual) "You can NOT map a Left value"))

  (let [e (Either.of "rank")
        map (e:map #(.. "f" $1))
        expected :frank
        actual (. map :value)
        ]
    (assert (= expected actual) "You can map a Either.of"))



)