(.module: {#.doc "Functionality for working with tuples (particularly 2-tuples)."} lux) ## [Functions] (template [ ] [(def: #export ( xy) (All [a b] (-> [a b] )) (let [[x y] xy] ))] [left a x] [right b y]) (def: #export (curry f) (All [a b c] (-> (-> [a b] c) (-> a b c))) (function (_ x y) (f [x y]))) (def: #export (uncurry f) (All [a b c] (-> (-> a b c) (-> [a b] c))) (function (_ 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 d] (-> (-> a c) (-> b d) (-> [a b] [c d]))) (function (_ [x y]) [(f x) (g y)])) (def: #export (fork f g) (All [a l r] (-> (-> a l) (-> a r) (-> a [l r]))) (function (_ x) [(f x) (g x)]))