From 4331551e030860116f5b6d23ad0d1259e1e7c048 Mon Sep 17 00:00:00 2001
From: Eduardo Julian
Date: Wed, 2 May 2018 00:35:41 -0400
Subject: - Added function for folding using monoids.

---
 stdlib/source/lux/control/monoid.lux | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

(limited to 'stdlib/source')

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)))
-- 
cgit v1.2.3