blob: 7c1552f41266bece053196ea3e0c7810f64e36d7 (
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
|
(.module:
[lux #*
["." io (#+ IO io)]
[control
["." monad (#+ do Monad)]
[concurrency
["." promise ("#/." monad)]
["." frp (#+ Channel)]
["." atom (#+ Atom atom)]]]
[data
["." number]
[collection
["." list]]]]
lux/test)
(context: "FRP"
(let [(^open "list/.") (list.equivalence number.equivalence)]
($_ seq
(wrap (do promise.monad
[output (|> (list +0 +1 +2 +3 +4 +5)
(frp.sequential 0)
(frp.filter i/even?)
frp.consume)]
(assert "Can filter a channel's elements."
(list/= (list +0 +2 +4) output))))
(wrap (do promise.monad
[output (|> (list +0 +1 +2 +3 +4 +5)
(frp.sequential 0)
(:: frp.functor map inc)
frp.consume)]
(assert "Functor goes over every element in a channel."
(list/= (list +1 +2 +3 +4 +5 +6)
output))))
(wrap (do promise.monad
[output (frp.consume (:: frp.apply apply
(frp.sequential 0 (list inc))
(frp.sequential 0 (list +12345))))]
(assert "Apply works over all channel values."
(list/= (list +12346)
output))))
(wrap (do promise.monad
[output (frp.consume
(do frp.monad
[f (frp.from-promise (promise/wrap inc))
a (frp.from-promise (promise/wrap +12345))]
(wrap (f a))))]
(assert "Valid monad."
(list/= (list +12346)
output))))
)))
|