add fx.Count

This commit is contained in:
kevin
2020-10-05 18:17:59 +08:00
parent 173b347c90
commit 637a94a189
2 changed files with 38 additions and 0 deletions

View File

@@ -84,6 +84,14 @@ func (p Stream) Buffer(n int) Stream {
return Range(source)
}
// Count counts the number of elements in the result.
func (p Stream) Count() (count int) {
for range p.source {
count++
}
return
}
// Distinct removes the duplicated items base on the given KeyFunc.
func (p Stream) Distinct(fn KeyFunc) Stream {
source := make(chan interface{})