blob: 2a25e53a093ed0f776e026b1dc77a60f491d82af (
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
|
(;module: {#;doc "Functionality for working with tuples (particularly 2-tuples)."}
lux)
## [Functions]
(do-template [<name> <type> <output>]
[(def: #export (<name> xy)
(All [a b] (-> [a b] <type>))
(let [[x y] xy]
<output>))]
[left a x]
[right b y])
(def: #export (curry f)
(All [a b c]
(-> (-> [a b] c)
(-> a b c)))
(lambda [x y]
(f [x y])))
(def: #export (uncurry f)
(All [a b c]
(-> (-> a b c) (-> [a b] c)))
(lambda [xy]
(let [[x y] xy]
(f x y))))
(def: #export (swap xy)
(All [a b] (-> [a b] [b a]))
(let [[x y] xy]
[y x]))
(def: #export (both f g)
(All [a b c] (-> (-> a b) (-> a c)
(-> a [b c])))
(lambda [input]
[(f input) (g input)]))
|