aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/abstract/fold.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/abstract/fold.lux')
-rw-r--r--stdlib/source/library/lux/abstract/fold.lux17
1 files changed, 17 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/abstract/fold.lux b/stdlib/source/library/lux/abstract/fold.lux
new file mode 100644
index 000000000..168d743be
--- /dev/null
+++ b/stdlib/source/library/lux/abstract/fold.lux
@@ -0,0 +1,17 @@
+(.module:
+ [library
+ [lux #*]]
+ [//
+ [monoid (#+ Monoid)]])
+
+(interface: #export (Fold F)
+ {#.doc "Iterate over a structure's values to build a summary value."}
+ (: (All [a b]
+ (-> (-> b a a) a (F b) a))
+ fold))
+
+(def: #export (with-monoid monoid fold value)
+ (All [F a]
+ (-> (Monoid a) (Fold F) (F a) a))
+ (let [(^open "/\.") monoid]
+ (fold /\compose /\identity value)))