blob: 8b2bef2186955a4085db1c4a5e133014d7613411 (
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
60
61
62
63
|
(.module:
[lux #*
[data
[text ("text/." Equivalence<Text>)]]])
(type: #export (PList a)
(List [Text a]))
(def: #export (get key properties)
(All [a] (-> Text (PList a) (Maybe a)))
(case properties
#.Nil
#.None
(#.Cons [k' v'] properties')
(if (text/= key k')
(#.Some v')
(get key properties'))))
(def: #export (contains? key properties)
(All [a] (-> Text (PList a) Bit))
(case (get key properties)
(#.Some _)
#1
#.None
#0))
(def: #export (put key val properties)
(All [a] (-> Text a (PList a) (PList a)))
(case properties
#.Nil
(list [key val])
(#.Cons [k' v'] properties')
(if (text/= key k')
(#.Cons [key val]
properties')
(#.Cons [k' v']
(put key val properties')))))
(def: #export (update key f properties)
(All [a] (-> Text (-> a a) (PList a) (PList a)))
(case properties
#.Nil
#.Nil
(#.Cons [k' v'] properties')
(if (text/= key k')
(#.Cons [k' (f v')] properties')
(#.Cons [k' v'] (update key f properties')))))
(def: #export (remove key properties)
(All [a] (-> Text (PList a) (PList a)))
(case properties
#.Nil
properties
(#.Cons [k' v'] properties')
(if (text/= key k')
properties'
(#.Cons [k' v']
(remove key properties')))))
|