feature: two evaluate operate func addtion in package stream (#3129)

Co-authored-by: Riven <Riven.chen@hairobotics.com>
This commit is contained in:
suplalalala
2023-04-16 23:14:25 +08:00
committed by GitHub
parent 757ed19dc5
commit 0d11ce03a8
2 changed files with 99 additions and 0 deletions

View File

@@ -540,3 +540,25 @@ func newOptions() *rxOptions {
workers: defaultWorkers,
}
}
// Max returns the maximum item from the underlying source.
func (s Stream) Max(less LessFunc) any {
var maxItem any = nil
for item := range s.source {
if maxItem == nil || less(maxItem, item) {
maxItem = item
}
}
return maxItem
}
// Min returns the minimum item from the underlying source.
func (s Stream) Min(less LessFunc) any {
var minItem any = nil
for item := range s.source {
if minItem == nil || !less(minItem, item) {
minItem = item
}
}
return minItem
}