aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/sum.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/sum.lux')
-rw-r--r--stdlib/source/lux/data/sum.lux24
1 files changed, 17 insertions, 7 deletions
diff --git a/stdlib/source/lux/data/sum.lux b/stdlib/source/lux/data/sum.lux
index c2373c238..1a58127c1 100644
--- a/stdlib/source/lux/data/sum.lux
+++ b/stdlib/source/lux/data/sum.lux
@@ -1,7 +1,7 @@
-(.module: {#.doc "Functionality for working with variants (particularly 2-variants)."}
+(.module:
+ {#.doc "Functionality for working with variants (particularly 2-variants)."}
lux)
-## [Values]
(do-template [<name> <type> <index>]
[(def: #export (<name> value)
(All [a b] (-> <type> (| a b)))
@@ -10,13 +10,23 @@
[left a +0]
[right b +1])
-(def: #export (either f g)
- (All [a b c] (-> (-> a c) (-> b c)
- (-> (| a b) c)))
+(def: #export (either fl fr)
+ (All [a b c]
+ (-> (-> a c) (-> b c)
+ (-> (| a b) c)))
(function [input]
(case input
- (+0 l) (f l)
- (+1 r) (g r))))
+ (+0 l) (fl l)
+ (+1 r) (fr r))))
+
+(def: #export (each fl fr)
+ (All [l l' r r']
+ (-> (-> l l') (-> r r')
+ (-> (| l r) (| l' r'))))
+ (function [input]
+ (case input
+ (+0 l) (+0 (fl l))
+ (+1 r) (+1 (fr r)))))
(do-template [<name> <side> <tag>]
[(def: #export (<name> es)