MCPcopy Create free account
hub / github.com/Soft/iter / Fold

Function Fold

iterator.go:333–339  ·  view source on GitHub ↗

Fold reduces Iterator using function fn.

(it Iterator[T], init B, fn func(B, T) B)

Source from the content-addressed store, hash-verified

331
332// Fold reduces Iterator using function fn.
333func Fold[T any, B any](it Iterator[T], init B, fn func(B, T) B) B {
334 ret := init
335 ForEach(it, func(v T) {
336 ret = fn(ret, v)
337 })
338 return ret
339}
340
341type fuseIter[T any] struct {
342 inner Iterator[T]

Callers 1

TestFoldFunction · 0.85

Calls 1

ForEachFunction · 0.85

Tested by 1

TestFoldFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…