blob: 7ac79b465826d98412dff8da845a48cd0967a89b (
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
52
53
54
55
56
57
58
59
|
(.module:
[lux #*
["_" test (#+ Test)]
["." io (#+ IO io)]
[abstract/monad (#+ do)]
[control
[concurrency
["." promise ("#@." monad)]
["." atom (#+ Atom atom)]]]
[data
[number
["." nat]]
[collection
["." list ("#@." functor)]]]
[math
["r" random]]]
{1
["." / (#+ Channel)]})
(def: #export test
Test
(let [(^open "list@.") (list.equivalence nat.equivalence)]
(do r.monad
[inputs (r.list 5 r.nat)
sample r.nat]
($_ _.and
(wrap (do promise.monad
[output (|> inputs
(/.sequential 0)
(/.filter n/even?)
/.consume)]
(_.assert "Can filter a channel's elements."
(list@= (list.filter n/even? inputs)
output))))
(wrap (do promise.monad
[output (|> inputs
(/.sequential 0)
(:: /.functor map inc)
/.consume)]
(_.assert "Functor goes over every element in a channel."
(list@= (list@map inc inputs)
output))))
(wrap (do promise.monad
[output (/.consume (:: /.apply apply
(/.sequential 0 (list inc))
(/.sequential 0 (list sample))))]
(_.assert "Apply works over all channel values."
(list@= (list (inc sample))
output))))
(wrap (do promise.monad
[output (/.consume
(do /.monad
[f (/.from-promise (promise@wrap inc))
a (/.from-promise (promise@wrap sample))]
(wrap (f a))))]
(_.assert "Valid monad."
(list@= (list (inc sample))
output))))
))))
|