blob: 2ff10dbf599b536e614b695dbcf238d107f0ba5e (
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
|
## Copyright (c) Eduardo Julian. All rights reserved.
## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
## If a copy of the MPL was not distributed with this file,
## You can obtain one at http://mozilla.org/MPL/2.0/.
(;module:
lux
(lux (codata [io])
(control monad)
(data sum
[text "Text/" Monoid<Text>]
[number]
(struct [list]))
(codata function)
pipe)
lux/test)
(test: "Sum operations"
(let [(^open "List/") (list;Eq<List> text;Eq<Text>)]
($_ seq
(assert "Can inject values into Either."
(and (|> (left "Hello") (case> (+0 "Hello") true _ false))
(|> (right "World") (case> (+1 "World") true _ false))))
(assert "Can discriminate eithers based on their cases."
(let [[_lefts _rights] (partition (: (List (| Text Text))
(list (+0 "0") (+1 "1") (+0 "2"))))]
(and (List/= _lefts
(lefts (: (List (| Text Text))
(list (+0 "0") (+1 "1") (+0 "2")))))
(List/= _rights
(rights (: (List (| Text Text))
(list (+0 "0") (+1 "1") (+0 "2"))))))))
(assert "Can apply a function to an Either value depending on the case."
(and (i.= 10 (either (lambda [_] 10) (lambda [_] 20) (: (| Text Text) (+0 ""))))
(i.= 20 (either (lambda [_] 10) (lambda [_] 20) (: (| Text Text) (+1 ""))))))
)))
|