1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-11-25 22:21:49 +02:00

fix: add traversal for sequences

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2025-11-14 14:12:44 +01:00
parent 2c1d8196b4
commit 02d0be9dad
15 changed files with 701 additions and 41 deletions

View File

@@ -77,8 +77,7 @@ func IsNonNil[GA ~[]A, A any](as GA) bool {
func Reduce[GA ~[]A, A, B any](fa GA, f func(B, A) B, initial B) B {
current := initial
count := len(fa)
for i := 0; i < count; i++ {
for i := range len(fa) {
current = f(current, fa[i])
}
return current
@@ -86,8 +85,7 @@ func Reduce[GA ~[]A, A, B any](fa GA, f func(B, A) B, initial B) B {
func ReduceWithIndex[GA ~[]A, A, B any](fa GA, f func(int, B, A) B, initial B) B {
current := initial
count := len(fa)
for i := 0; i < count; i++ {
for i := range len(fa) {
current = f(i, current, fa[i])
}
return current