aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2018-05-02 00:35:41 -0400
committerEduardo Julian2018-05-02 00:35:41 -0400
commit4331551e030860116f5b6d23ad0d1259e1e7c048 (patch)
tree6729373786930fcf45f5a2ec7f2475e0556055f9
parent7237639429cf766ca63cdcfd87a603fa0616f29d (diff)
- Added function for folding using monoids.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/monoid.lux21
1 files changed, 14 insertions, 7 deletions
diff --git a/stdlib/source/lux/control/monoid.lux b/stdlib/source/lux/control/monoid.lux
index c073bdb0b..09737cb12 100644
--- a/stdlib/source/lux/control/monoid.lux
+++ b/stdlib/source/lux/control/monoid.lux
@@ -1,4 +1,5 @@
-(.module: lux)
+(.module: lux
+ (// [fold #+ Fold]))
(sig: #export (Monoid a)
{#.doc "A way to compose values.
@@ -11,9 +12,15 @@
(def: #export (compose Monoid<l> Monoid<r>)
(All [l r] (-> (Monoid l) (Monoid r) (Monoid [l r])))
- (struct (def: identity
- [(:: Monoid<l> identity) (:: Monoid<r> identity)])
-
- (def: (compose [lL rL] [lR rR])
- [(:: Monoid<l> compose lL lR)
- (:: Monoid<r> compose rL rR)])))
+ (struct
+ (def: identity
+ [(:: Monoid<l> identity) (:: Monoid<r> identity)])
+
+ (def: (compose [lL rL] [lR rR])
+ [(:: Monoid<l> compose lL lR)
+ (:: Monoid<r> compose rL rR)])))
+
+(def: #export (fold Monoid<a> Fold<F> data)
+ (All [a F] (-> (Monoid a) (Fold F) (F a) a))
+ (let [(^open "a/") Monoid<a>]
+ (:: Fold<F> fold a/compose a/identity data)))