aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/product.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/data/product.lux')
-rw-r--r--stdlib/source/library/lux/data/product.lux35
1 files changed, 21 insertions, 14 deletions
diff --git a/stdlib/source/library/lux/data/product.lux b/stdlib/source/library/lux/data/product.lux
index 6cf05ac83..25e6b02d0 100644
--- a/stdlib/source/library/lux/data/product.lux
+++ b/stdlib/source/library/lux/data/product.lux
@@ -1,52 +1,59 @@
(.module:
- {#.doc "Functionality for working with tuples (particularly 2-tuples)."}
+ {#.doc "Functionality for working with tuples (particularly 2-tuples/pairs)."}
[library
[lux #*
[abstract
[equivalence (#+ Equivalence)]
[hash (#+ Hash)]]]])
-(template [<name> <type> <output>]
- [(def: #export (<name> xy)
- (All [a b] (-> (& a b) <type>))
- (let [[x y] xy]
- <output>))]
+(template [<name> <doc>]
+ [(def: #export (<name> pair)
+ {#.doc (doc <doc>)}
+ (All [left right]
+ (-> [left right] <name>))
+ (let [[left right] pair]
+ <name>))]
- [left a x]
- [right b y]
+ [left "The left side of a pair."]
+ [right "The right side of a pair."]
)
+## https://en.wikipedia.org/wiki/Currying
(def: #export (curry f)
+ {#.doc (doc "Converts a 2-argument function into nested single-argument functions.")}
(All [a b c]
- (-> (-> (& a b) c)
+ (-> (-> [a b] c)
(-> a b c)))
(function (_ x y)
(f [x y])))
(def: #export (uncurry f)
+ {#.doc (doc "Converts nested single-argument functions into a 2-argument function.")}
(All [a b c]
(-> (-> 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)))
+ (All [a b] (-> [a b] [b a]))
(let [[x y] xy]
[y x]))
(def: #export (apply f g)
+ {#.doc (doc "Apply functions to both sides of a pair.")}
(All [a b c d]
(-> (-> a c) (-> b d)
- (-> (& a b) (& c d))))
+ (-> [a b] [c d])))
(function (_ [x y])
[(f x) (g y)]))
(def: #export (fork f g)
+ {#.doc (doc "Yields a pair by applying both functions to a single value.")}
(All [a l r]
(-> (-> a l) (-> a r)
- (-> a (& l r))))
+ (-> a [l r])))
(function (_ x)
[(f x) (g x)]))
@@ -58,7 +65,7 @@
(\ right = rr sr))))
(def: #export (hash left right)
- (All [l r] (-> (Hash l) (Hash r) (Hash (& l r))))
+ (All [l r] (-> (Hash l) (Hash r) (Hash [l r])))
(implementation
(def: &equivalence
(..equivalence (\ left &equivalence)