blob: 56c048593553ebeefbdd16ed773b39e3b946241c (
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
|
(.module:
lux
(lux (control [monoid #+ Monoid])
(data (coll (set ["set" unordered #+ Set])))
[function]))
(type: #export (Predicate a)
(-> a Bool))
(do-template [<identity-name> <identity-value> <composition-name> <composition>]
[(def: #export <identity-name>
(All [a] (Predicate a))
(function.constant <identity-value>))
(def: #export (<composition-name> left right)
(All [a] (-> (Predicate a) (Predicate a) (Predicate a)))
(function (_ value)
(<composition> (left value)
(right value))))]
[none false union or]
[all true intersection and]
)
(do-template [<name> <identity> <composition>]
[(structure: #export <name> (All [a] (Monoid (Predicate a)))
(def: identity <identity>)
(def: compose <composition>))]
[Union@Monoid none union]
[Intersection@Monoid all intersection]
)
(def: #export (complement predicate)
(All [a] (-> (Predicate a) (Predicate a)))
(|>> predicate not))
(def: #export (difference sub base)
(All [a] (-> (Predicate a) (Predicate a) (Predicate a)))
(function (_ value)
(and (base value)
(not (sub value)))))
(def: #export (set set)
(All [a] (-> (Set a) (Predicate a)))
(set.member? set))
(def: #export (rec predicate)
(All [a]
(-> (-> (Predicate a) (Predicate a))
(Predicate a)))
(|>> (predicate (rec predicate))))
|