mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-02 16:28:39 +08:00
chore: refactor max/min in fx (#3135)
This commit is contained in:
parent
0d11ce03a8
commit
bbfce6abe9
@ -292,6 +292,18 @@ func (s Stream) Map(fn MapFunc, opts ...Option) Stream {
|
|||||||
}, opts...)
|
}, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Max returns the maximum item from the underlying source.
|
||||||
|
func (s Stream) Max(less LessFunc) any {
|
||||||
|
var max any
|
||||||
|
for item := range s.source {
|
||||||
|
if max == nil || less(max, item) {
|
||||||
|
max = item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
// Merge merges all the items into a slice and generates a new stream.
|
// Merge merges all the items into a slice and generates a new stream.
|
||||||
func (s Stream) Merge() Stream {
|
func (s Stream) Merge() Stream {
|
||||||
var items []any
|
var items []any
|
||||||
@ -306,6 +318,18 @@ func (s Stream) Merge() Stream {
|
|||||||
return Range(source)
|
return Range(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Min returns the minimum item from the underlying source.
|
||||||
|
func (s Stream) Min(less LessFunc) any {
|
||||||
|
var min any
|
||||||
|
for item := range s.source {
|
||||||
|
if min == nil || less(item, min) {
|
||||||
|
min = item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
|
||||||
// NoneMatch returns whether all elements of this stream don't match the provided predicate.
|
// NoneMatch returns whether all elements of this stream don't match the provided predicate.
|
||||||
// May not evaluate the predicate on all elements if not necessary for determining the result.
|
// May not evaluate the predicate on all elements if not necessary for determining the result.
|
||||||
// If the stream is empty then true is returned and the predicate is not evaluated.
|
// If the stream is empty then true is returned and the predicate is not evaluated.
|
||||||
@ -540,25 +564,3 @@ func newOptions() *rxOptions {
|
|||||||
workers: defaultWorkers,
|
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
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user