Fold reduces Iterator using function fn.
(it Iterator[T], init B, fn func(B, T) B)
| 331 | |
| 332 | // Fold reduces Iterator using function fn. |
| 333 | func 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 | |
| 341 | type fuseIter[T any] struct { |
| 342 | inner Iterator[T] |