chore: change interface{} to any (#2818)

* chore: change interface{} to any

* chore: update goctl version to 1.5.0

* chore: update goctl deps
This commit is contained in:
Kevin Wan
2023-01-24 16:32:02 +08:00
committed by GitHub
parent 7e0ac77139
commit ae87114282
221 changed files with 1910 additions and 2207 deletions

View File

@@ -21,31 +21,31 @@ type (
}
// FilterFunc defines the method to filter a Stream.
FilterFunc func(item interface{}) bool
FilterFunc func(item any) bool
// ForAllFunc defines the method to handle all elements in a Stream.
ForAllFunc func(pipe <-chan interface{})
ForAllFunc func(pipe <-chan any)
// ForEachFunc defines the method to handle each element in a Stream.
ForEachFunc func(item interface{})
ForEachFunc func(item any)
// GenerateFunc defines the method to send elements into a Stream.
GenerateFunc func(source chan<- interface{})
GenerateFunc func(source chan<- any)
// KeyFunc defines the method to generate keys for the elements in a Stream.
KeyFunc func(item interface{}) interface{}
KeyFunc func(item any) any
// LessFunc defines the method to compare the elements in a Stream.
LessFunc func(a, b interface{}) bool
LessFunc func(a, b any) bool
// MapFunc defines the method to map each element to another object in a Stream.
MapFunc func(item interface{}) interface{}
MapFunc func(item any) any
// Option defines the method to customize a Stream.
Option func(opts *rxOptions)
// ParallelFunc defines the method to handle elements parallelly.
ParallelFunc func(item interface{})
ParallelFunc func(item any)
// ReduceFunc defines the method to reduce all the elements in a Stream.
ReduceFunc func(pipe <-chan interface{}) (interface{}, error)
ReduceFunc func(pipe <-chan any) (any, error)
// WalkFunc defines the method to walk through all the elements in a Stream.
WalkFunc func(item interface{}, pipe chan<- interface{})
WalkFunc func(item any, pipe chan<- any)
// A Stream is a stream that can be used to do stream processing.
Stream struct {
source <-chan interface{}
source <-chan any
}
)
@@ -56,7 +56,7 @@ func Concat(s Stream, others ...Stream) Stream {
// From constructs a Stream from the given GenerateFunc.
func From(generate GenerateFunc) Stream {
source := make(chan interface{})
source := make(chan any)
threading.GoSafe(func() {
defer close(source)
@@ -67,8 +67,8 @@ func From(generate GenerateFunc) Stream {
}
// Just converts the given arbitrary items to a Stream.
func Just(items ...interface{}) Stream {
source := make(chan interface{}, len(items))
func Just(items ...any) Stream {
source := make(chan any, len(items))
for _, item := range items {
source <- item
}
@@ -78,7 +78,7 @@ func Just(items ...interface{}) Stream {
}
// Range converts the given channel to a Stream.
func Range(source <-chan interface{}) Stream {
func Range(source <-chan any) Stream {
return Stream{
source: source,
}
@@ -87,7 +87,7 @@ func Range(source <-chan interface{}) Stream {
// AllMach returns whether all elements of this stream match the provided predicate.
// 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.
func (s Stream) AllMach(predicate func(item interface{}) bool) bool {
func (s Stream) AllMach(predicate func(item any) bool) bool {
for item := range s.source {
if !predicate(item) {
// make sure the former goroutine not block, and current func returns fast.
@@ -102,7 +102,7 @@ func (s Stream) AllMach(predicate func(item interface{}) bool) bool {
// AnyMach returns whether any elements of this stream match the provided predicate.
// May not evaluate the predicate on all elements if not necessary for determining the result.
// If the stream is empty then false is returned and the predicate is not evaluated.
func (s Stream) AnyMach(predicate func(item interface{}) bool) bool {
func (s Stream) AnyMach(predicate func(item any) bool) bool {
for item := range s.source {
if predicate(item) {
// make sure the former goroutine not block, and current func returns fast.
@@ -121,7 +121,7 @@ func (s Stream) Buffer(n int) Stream {
n = 0
}
source := make(chan interface{}, n)
source := make(chan any, n)
go func() {
for item := range s.source {
source <- item
@@ -134,7 +134,7 @@ func (s Stream) Buffer(n int) Stream {
// Concat returns a Stream that concatenated other streams
func (s Stream) Concat(others ...Stream) Stream {
source := make(chan interface{})
source := make(chan any)
go func() {
group := threading.NewRoutineGroup()
@@ -170,12 +170,12 @@ func (s Stream) Count() (count int) {
// Distinct removes the duplicated items base on the given KeyFunc.
func (s Stream) Distinct(fn KeyFunc) Stream {
source := make(chan interface{})
source := make(chan any)
threading.GoSafe(func() {
defer close(source)
keys := make(map[interface{}]lang.PlaceholderType)
keys := make(map[any]lang.PlaceholderType)
for item := range s.source {
key := fn(item)
if _, ok := keys[key]; !ok {
@@ -195,7 +195,7 @@ func (s Stream) Done() {
// Filter filters the items by the given FilterFunc.
func (s Stream) Filter(fn FilterFunc, opts ...Option) Stream {
return s.Walk(func(item interface{}, pipe chan<- interface{}) {
return s.Walk(func(item any, pipe chan<- any) {
if fn(item) {
pipe <- item
}
@@ -203,7 +203,7 @@ func (s Stream) Filter(fn FilterFunc, opts ...Option) Stream {
}
// First returns the first item, nil if no items.
func (s Stream) First() interface{} {
func (s Stream) First() any {
for item := range s.source {
// make sure the former goroutine not block, and current func returns fast.
go drain(s.source)
@@ -229,13 +229,13 @@ func (s Stream) ForEach(fn ForEachFunc) {
// Group groups the elements into different groups based on their keys.
func (s Stream) Group(fn KeyFunc) Stream {
groups := make(map[interface{}][]interface{})
groups := make(map[any][]any)
for item := range s.source {
key := fn(item)
groups[key] = append(groups[key], item)
}
source := make(chan interface{})
source := make(chan any)
go func() {
for _, group := range groups {
source <- group
@@ -252,7 +252,7 @@ func (s Stream) Head(n int64) Stream {
panic("n must be greater than 0")
}
source := make(chan interface{})
source := make(chan any)
go func() {
for item := range s.source {
@@ -279,7 +279,7 @@ func (s Stream) Head(n int64) Stream {
}
// Last returns the last item, or nil if no items.
func (s Stream) Last() (item interface{}) {
func (s Stream) Last() (item any) {
for item = range s.source {
}
return
@@ -287,19 +287,19 @@ func (s Stream) Last() (item interface{}) {
// Map converts each item to another corresponding item, which means it's a 1:1 model.
func (s Stream) Map(fn MapFunc, opts ...Option) Stream {
return s.Walk(func(item interface{}, pipe chan<- interface{}) {
return s.Walk(func(item any, pipe chan<- any) {
pipe <- fn(item)
}, opts...)
}
// Merge merges all the items into a slice and generates a new stream.
func (s Stream) Merge() Stream {
var items []interface{}
var items []any
for item := range s.source {
items = append(items, item)
}
source := make(chan interface{}, 1)
source := make(chan any, 1)
source <- items
close(source)
@@ -309,7 +309,7 @@ func (s Stream) Merge() Stream {
// 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.
// If the stream is empty then true is returned and the predicate is not evaluated.
func (s Stream) NoneMatch(predicate func(item interface{}) bool) bool {
func (s Stream) NoneMatch(predicate func(item any) bool) bool {
for item := range s.source {
if predicate(item) {
// make sure the former goroutine not block, and current func returns fast.
@@ -323,19 +323,19 @@ func (s Stream) NoneMatch(predicate func(item interface{}) bool) bool {
// Parallel applies the given ParallelFunc to each item concurrently with given number of workers.
func (s Stream) Parallel(fn ParallelFunc, opts ...Option) {
s.Walk(func(item interface{}, pipe chan<- interface{}) {
s.Walk(func(item any, pipe chan<- any) {
fn(item)
}, opts...).Done()
}
// Reduce is an utility method to let the caller deal with the underlying channel.
func (s Stream) Reduce(fn ReduceFunc) (interface{}, error) {
func (s Stream) Reduce(fn ReduceFunc) (any, error) {
return fn(s.source)
}
// Reverse reverses the elements in the stream.
func (s Stream) Reverse() Stream {
var items []interface{}
var items []any
for item := range s.source {
items = append(items, item)
}
@@ -357,7 +357,7 @@ func (s Stream) Skip(n int64) Stream {
return s
}
source := make(chan interface{})
source := make(chan any)
go func() {
for item := range s.source {
@@ -376,7 +376,7 @@ func (s Stream) Skip(n int64) Stream {
// Sort sorts the items from the underlying source.
func (s Stream) Sort(less LessFunc) Stream {
var items []interface{}
var items []any
for item := range s.source {
items = append(items, item)
}
@@ -394,9 +394,9 @@ func (s Stream) Split(n int) Stream {
panic("n should be greater than 0")
}
source := make(chan interface{})
source := make(chan any)
go func() {
var chunk []interface{}
var chunk []any
for item := range s.source {
chunk = append(chunk, item)
if len(chunk) == n {
@@ -419,7 +419,7 @@ func (s Stream) Tail(n int64) Stream {
panic("n should be greater than 0")
}
source := make(chan interface{})
source := make(chan any)
go func() {
ring := collection.NewRing(int(n))
@@ -446,7 +446,7 @@ func (s Stream) Walk(fn WalkFunc, opts ...Option) Stream {
}
func (s Stream) walkLimited(fn WalkFunc, option *rxOptions) Stream {
pipe := make(chan interface{}, option.workers)
pipe := make(chan any, option.workers)
go func() {
var wg sync.WaitGroup
@@ -477,7 +477,7 @@ func (s Stream) walkLimited(fn WalkFunc, option *rxOptions) Stream {
}
func (s Stream) walkUnlimited(fn WalkFunc, option *rxOptions) Stream {
pipe := make(chan interface{}, option.workers)
pipe := make(chan any, option.workers)
go func() {
var wg sync.WaitGroup
@@ -529,7 +529,7 @@ func buildOptions(opts ...Option) *rxOptions {
}
// drain drains the given channel.
func drain(channel <-chan interface{}) {
func drain(channel <-chan any) {
for range channel {
}
}