feature: two evaluate operate func addtion in package stream (#3129)
Co-authored-by: Riven <Riven.chen@hairobotics.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user