Skip to content

Commit

Permalink
fix: seq.Reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
m4gshm committed Jun 29, 2024
1 parent 2edab07 commit 76fe4d6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions seq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ func Reduce[T any](seq iter.Seq[T], merge func(T, T) T) (result T, ok bool) {
if seq == nil {
return result, false
}
seq(func(v T) bool { result = v; return true })
for v := range seq {
result = merge(result, v)
}
first := true
seq(func(v T) bool {
if first {
result = v
} else {
result = merge(result, v)
}
first = false
return true
})
return result, true
}

Expand Down

0 comments on commit 76fe4d6

Please sign in to comment.