1 Star 0 Fork 0

sy_183 / go-common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
consumer.go 572 Bytes
一键复制 编辑 原始数据 按行查看 历史
package iter
func ForEach[V any](action func(v V), iter Iter[V]) {
for {
if v, ok := iter(); ok {
action(v)
} else {
return
}
}
}
func Reduce[V, R any](reducer func(cur R, v V) R, init R, iter Iter[V]) R {
for {
if v, ok := iter(); ok {
init = reducer(init, v)
} else {
return init
}
}
}
func Collect[V any](iter Iter[V]) (vs []V) {
for {
if v, ok := iter(); ok {
vs = append(vs, v)
} else {
return
}
}
}
func Count[V any](iter Iter[V]) (count int) {
for {
if _, ok := iter(); ok {
count++
} else {
return
}
}
}
1
https://gitee.com/sy_183/go-common.git
git@gitee.com:sy_183/go-common.git
sy_183
go-common
go-common
v1.0.4

搜索帮助