From 1aa0e8f2d10e4a3b32fab5e2b88f63e1e4c38f98 Mon Sep 17 00:00:00 2001 From: Farbod Salimi <4585739+farbodsalimi@users.noreply.github.com> Date: Wed, 1 Feb 2023 17:16:15 -0800 Subject: [PATCH] docs: add fold --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 8dbe9bf..a03a2c2 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Goulash provides a bunch of useful functional programming helpers leveraging Go - [Contains](#contains) - [Difference](#difference) - [Filter](#filter) + - [Fold](#fold) - [ForEach](#foreach) - [GroupBy](#groupby) - [Intersection](#intersection) @@ -145,6 +146,15 @@ filtered := __.Filter([]int{1, 2, 3, 4, 5, 6}, func(n int) bool { fmt.Println(filtered) // [1 3 5] ``` +### Fold + +```go +folded := __.Fold([]int{1, 2, 3}, 0, func(a int, b int) int { + return a + b +}) +fmt.Println(folded) // 6 +``` + ### ForEach ```go