重命名
This commit is contained in:
parent
e94165f63c
commit
a983f90881
|
@ -24,11 +24,11 @@ func newMapX[K comparable, V any]() mapX[K, V] {
|
|||
}
|
||||
}
|
||||
|
||||
func SimpleMapFilterAndMapToSlice[R any, K comparable, V any](mm SimpleMapStream[K, V], fn func(K, V) (R, bool)) SimpleSliceStream[R] {
|
||||
return NewSimpleSliceStream(maps.FilterToSlice(mm.m, fn))
|
||||
func SimpleMapFilterAndMapToSlice[R any, K comparable, V any](mm MapStream[K, V], fn func(K, V) (R, bool)) Stream[R] {
|
||||
return NewStream(maps.FilterToSlice(mm.m, fn))
|
||||
}
|
||||
|
||||
func SimpleMapParallelFilterAndMapToMap[K comparable, V any, KK comparable, VV any](mm SimpleMapStream[KK, VV], fn func(KK, VV) (K, V, bool), c int) SimpleMapStream[K, V] {
|
||||
func SimpleMapParallelFilterAndMapToMap[K comparable, V any, KK comparable, VV any](mm MapStream[KK, VV], fn func(KK, VV) (K, V, bool), c int) MapStream[K, V] {
|
||||
m := newMapX[K, V]()
|
||||
mm.ParallelForEach(func(kk KK, vv VV) {
|
||||
k, v, ok := fn(kk, vv)
|
||||
|
@ -36,11 +36,11 @@ func SimpleMapParallelFilterAndMapToMap[K comparable, V any, KK comparable, VV a
|
|||
m.set(k, v)
|
||||
}
|
||||
}, c)
|
||||
return SimpleMapStream[K, V]{m.m}
|
||||
return MapStream[K, V]{m.m}
|
||||
}
|
||||
|
||||
func SimpleMapStreamFilterAndMapToMap[K comparable, V any, KK comparable, VV comparable](a SimpleMapStream[KK, VV], fn func(KK, VV) (K, V, bool)) (r SimpleMapStream[K, V]) {
|
||||
r = SimpleMapStream[K, V]{make(map[K]V)}
|
||||
func SimpleMapStreamFilterAndMapToMap[K comparable, V any, KK comparable, VV comparable](a MapStream[KK, VV], fn func(KK, VV) (K, V, bool)) (r MapStream[K, V]) {
|
||||
r = MapStream[K, V]{make(map[K]V)}
|
||||
for k, v := range a.m {
|
||||
kk, vv, ok := fn(k, v)
|
||||
if ok {
|
||||
|
@ -50,21 +50,21 @@ func SimpleMapStreamFilterAndMapToMap[K comparable, V any, KK comparable, VV com
|
|||
return
|
||||
}
|
||||
|
||||
func NewSimpleMapStream[K comparable, V any](m map[K]V) SimpleMapStream[K, V] {
|
||||
return SimpleMapStream[K, V]{m}
|
||||
func NewSimpleMapStream[K comparable, V any](m map[K]V) MapStream[K, V] {
|
||||
return MapStream[K, V]{m}
|
||||
}
|
||||
|
||||
type SimpleMapStream[K comparable, V any] struct {
|
||||
type MapStream[K comparable, V any] struct {
|
||||
m map[K]V
|
||||
}
|
||||
|
||||
func (r SimpleMapStream[K, V]) ForEach(fn func(K, V)) {
|
||||
func (r MapStream[K, V]) ForEach(fn func(K, V)) {
|
||||
for k, v := range r.m {
|
||||
fn(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (r SimpleMapStream[K, V]) ParallelForEach(fn func(K, V), c int) {
|
||||
func (r MapStream[K, V]) ParallelForEach(fn func(K, V), c int) {
|
||||
p := taskPools.NewPools(c)
|
||||
for k, v := range r.m {
|
||||
k := k
|
||||
|
@ -76,10 +76,10 @@ func (r SimpleMapStream[K, V]) ParallelForEach(fn func(K, V), c int) {
|
|||
p.Wait()
|
||||
}
|
||||
|
||||
func (r SimpleMapStream[K, V]) Len() int {
|
||||
func (r MapStream[K, V]) Len() int {
|
||||
return len(r.m)
|
||||
}
|
||||
|
||||
func (r SimpleMapStream[K, V]) Result() map[K]V {
|
||||
func (r MapStream[K, V]) Result() map[K]V {
|
||||
return r.m
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ func TestNewSimpleMapStream(t *testing.T) {
|
|||
type testCase[K int, V int] struct {
|
||||
name string
|
||||
args args[K, V]
|
||||
want SimpleMapStream[K, V]
|
||||
want MapStream[K, V]
|
||||
}
|
||||
tests := []testCase[int, int]{
|
||||
{
|
||||
name: "t1",
|
||||
args: args[int, int]{make(map[int]int)},
|
||||
want: SimpleMapStream[int, int]{make(map[int]int)},
|
||||
want: MapStream[int, int]{make(map[int]int)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -41,14 +41,14 @@ var w = slice.ToMap(y, func(v int) (int, int) {
|
|||
|
||||
func TestSimpleMapFilterAndMapToSlice(t *testing.T) {
|
||||
type args[K int, V int, R int] struct {
|
||||
mm SimpleMapStream[K, V]
|
||||
mm MapStream[K, V]
|
||||
fn func(K, V) (R, bool)
|
||||
c int
|
||||
}
|
||||
type testCase[K int, V int, R int] struct {
|
||||
name string
|
||||
args args[K, V, R]
|
||||
want SimpleSliceStream[R]
|
||||
want Stream[R]
|
||||
}
|
||||
tests := []testCase[int, int, int]{
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ func TestSimpleMapFilterAndMapToSlice(t *testing.T) {
|
|||
},
|
||||
c: 6,
|
||||
},
|
||||
want: NewSimpleSliceStream(y[500:]),
|
||||
want: NewStream(y[500:]),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -79,14 +79,14 @@ func TestSimpleMapFilterAndMapToSlice(t *testing.T) {
|
|||
|
||||
func TestSimpleMapParallelFilterAndMapToMap(t *testing.T) {
|
||||
type args[KK string, VV string, K int, V int] struct {
|
||||
mm SimpleMapStream[K, V]
|
||||
mm MapStream[K, V]
|
||||
fn func(K, V) (KK, VV, bool)
|
||||
c int
|
||||
}
|
||||
type testCase[KK string, VV string, K int, V int] struct {
|
||||
name string
|
||||
args args[KK, VV, K, V]
|
||||
want SimpleMapStream[KK, VV]
|
||||
want MapStream[KK, VV]
|
||||
}
|
||||
tests := []testCase[string, string, int, int]{
|
||||
{
|
||||
|
@ -119,13 +119,13 @@ func TestSimpleMapParallelFilterAndMapToMap(t *testing.T) {
|
|||
|
||||
func TestSimpleMapStreamFilterAndMapToMap(t *testing.T) {
|
||||
type args[KK string, VV string, K int, V int] struct {
|
||||
a SimpleMapStream[K, V]
|
||||
a MapStream[K, V]
|
||||
fn func(K, V) (KK, VV, bool)
|
||||
}
|
||||
type testCase[KK string, VV string, K int, V int] struct {
|
||||
name string
|
||||
args args[KK, VV, K, V]
|
||||
wantR SimpleMapStream[KK, VV]
|
||||
wantR MapStream[KK, VV]
|
||||
}
|
||||
tests := []testCase[string, string, int, int]{
|
||||
{
|
||||
|
@ -161,7 +161,7 @@ func TestSimpleMapStream_ForEach(t *testing.T) {
|
|||
}
|
||||
type testCase[K int, V int] struct {
|
||||
name string
|
||||
r SimpleMapStream[K, V]
|
||||
r MapStream[K, V]
|
||||
args args[K, V]
|
||||
}
|
||||
tests := []testCase[int, int]{
|
||||
|
@ -187,7 +187,7 @@ func TestSimpleMapStream_ForEach(t *testing.T) {
|
|||
func TestSimpleMapStream_Len(t *testing.T) {
|
||||
type testCase[K int, V int] struct {
|
||||
name string
|
||||
r SimpleMapStream[K, V]
|
||||
r MapStream[K, V]
|
||||
want int
|
||||
}
|
||||
tests := []testCase[int, int]{
|
||||
|
@ -213,7 +213,7 @@ func TestSimpleMapStream_ParallelForEach(t *testing.T) {
|
|||
}
|
||||
type testCase[K int, V int] struct {
|
||||
name string
|
||||
r SimpleMapStream[K, V]
|
||||
r MapStream[K, V]
|
||||
args args[K, V]
|
||||
}
|
||||
tests := []testCase[int, int]{
|
||||
|
@ -238,7 +238,7 @@ func TestSimpleMapStream_ParallelForEach(t *testing.T) {
|
|||
func TestSimpleMapStream_Result(t *testing.T) {
|
||||
type testCase[K int, V int] struct {
|
||||
name string
|
||||
r SimpleMapStream[K, V]
|
||||
r MapStream[K, V]
|
||||
want map[K]V
|
||||
}
|
||||
tests := []testCase[int, int]{
|
||||
|
|
|
@ -1,149 +0,0 @@
|
|||
package stream
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"github.com/fthvgb1/wp-go/taskPools"
|
||||
)
|
||||
|
||||
func SimpleParallelFilterAndMap[R, T any](a SimpleSliceStream[T], fn func(T) (R, bool), c int) SimpleSliceStream[R] {
|
||||
var x []R
|
||||
rr := safety.NewSlice(x)
|
||||
a.ParallelForEach(func(t T) {
|
||||
y, ok := fn(t)
|
||||
if ok {
|
||||
rr.Append(y)
|
||||
}
|
||||
}, c)
|
||||
return SimpleSliceStream[R]{rr.Load()}
|
||||
}
|
||||
|
||||
func SimpleParallelFilterAndMapToMap[K comparable, V any, T any](a SimpleSliceStream[T], fn func(t T) (K, V, bool), c int) (r SimpleMapStream[K, V]) {
|
||||
m := newMapX[K, V]()
|
||||
a.ParallelForEach(func(t T) {
|
||||
k, v, ok := fn(t)
|
||||
if ok {
|
||||
m.set(k, v)
|
||||
}
|
||||
}, c)
|
||||
var mm = map[K]V{}
|
||||
r = NewSimpleMapStream(mm)
|
||||
return
|
||||
}
|
||||
|
||||
func SimpleSliceFilterAndMapToMap[K comparable, V any, T any](a SimpleSliceStream[T], fn func(t T) (K, V, bool), isCoverPrev bool) (r SimpleMapStream[K, V]) {
|
||||
m := make(map[K]V)
|
||||
a.ForEach(func(t T) {
|
||||
k, v, ok := fn(t)
|
||||
if ok {
|
||||
_, ok = m[k]
|
||||
if isCoverPrev || !ok {
|
||||
m[k] = v
|
||||
}
|
||||
}
|
||||
})
|
||||
r.m = m
|
||||
return
|
||||
}
|
||||
|
||||
func SimpleStreamFilterAndMap[R, T any](a SimpleSliceStream[T], fn func(T) (R, bool)) SimpleSliceStream[R] {
|
||||
return NewSimpleSliceStream(slice.FilterAndMap(a.arr, fn))
|
||||
}
|
||||
|
||||
func SimpleParallelMap[R, T any](a SimpleSliceStream[T], fn func(T) R, c int) SimpleSliceStream[R] {
|
||||
var x []R
|
||||
rr := safety.NewSlice(x)
|
||||
a.ParallelForEach(func(t T) {
|
||||
rr.Append(fn(t))
|
||||
}, c)
|
||||
return SimpleSliceStream[R]{rr.Load()}
|
||||
}
|
||||
func SimpleStreamMap[R, T any](a SimpleSliceStream[T], fn func(T) R) SimpleSliceStream[R] {
|
||||
return NewSimpleSliceStream(slice.Map(a.arr, fn))
|
||||
}
|
||||
|
||||
func Reduce[T any, S any](s SimpleSliceStream[S], fn func(S, T) T, init T) (r T) {
|
||||
return slice.Reduce(s.arr, fn, init)
|
||||
}
|
||||
|
||||
func NewSimpleSliceStream[T any](arr []T) SimpleSliceStream[T] {
|
||||
return SimpleSliceStream[T]{arr: arr}
|
||||
}
|
||||
|
||||
type SimpleSliceStream[T any] struct {
|
||||
arr []T
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) ForEach(fn func(T)) {
|
||||
for _, t := range r.arr {
|
||||
fn(t)
|
||||
}
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) ParallelForEach(fn func(T), c int) {
|
||||
p := taskPools.NewPools(c)
|
||||
for _, t := range r.arr {
|
||||
t := t
|
||||
p.Execute(func() {
|
||||
fn(t)
|
||||
})
|
||||
}
|
||||
p.Wait()
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) ParallelFilter(fn func(T) bool, c int) SimpleSliceStream[T] {
|
||||
rr := safety.NewSlice([]T{})
|
||||
r.ParallelForEach(func(t T) {
|
||||
if fn(t) {
|
||||
rr.Append(t)
|
||||
}
|
||||
}, c)
|
||||
return SimpleSliceStream[T]{rr.Load()}
|
||||
}
|
||||
func (r SimpleSliceStream[T]) Filter(fn func(T) bool) SimpleSliceStream[T] {
|
||||
r.arr = slice.Filter(r.arr, fn)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) ParallelMap(fn func(T) T, c int) SimpleSliceStream[T] {
|
||||
rr := safety.NewSlice([]T{})
|
||||
r.ParallelForEach(func(t T) {
|
||||
rr.Append(fn(t))
|
||||
}, c)
|
||||
return SimpleSliceStream[T]{rr.Load()}
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) Map(fn func(T) T) SimpleSliceStream[T] {
|
||||
r.arr = slice.Map(r.arr, fn)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) Sort(fn func(i, j T) bool) SimpleSliceStream[T] {
|
||||
slice.SortSelf(r.arr, fn)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) Len() int {
|
||||
return len(r.arr)
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) Limit(limit, offset int) SimpleSliceStream[T] {
|
||||
l := len(r.arr)
|
||||
if offset >= l {
|
||||
return SimpleSliceStream[T]{}
|
||||
}
|
||||
ll := offset + limit
|
||||
if ll > l {
|
||||
ll = l
|
||||
}
|
||||
return SimpleSliceStream[T]{r.arr[offset:ll]}
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) Reverse() SimpleSliceStream[T] {
|
||||
slice.ReverseSelf(r.arr)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r SimpleSliceStream[T]) Result() []T {
|
||||
return r.arr
|
||||
}
|
149
stream/stream.go
Normal file
149
stream/stream.go
Normal file
|
@ -0,0 +1,149 @@
|
|||
package stream
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"github.com/fthvgb1/wp-go/taskPools"
|
||||
)
|
||||
|
||||
func ParallelFilterAndMap[R, T any](a Stream[T], fn func(T) (R, bool), c int) Stream[R] {
|
||||
var x []R
|
||||
rr := safety.NewSlice(x)
|
||||
a.ParallelForEach(func(t T) {
|
||||
y, ok := fn(t)
|
||||
if ok {
|
||||
rr.Append(y)
|
||||
}
|
||||
}, c)
|
||||
return Stream[R]{rr.Load()}
|
||||
}
|
||||
|
||||
func ParallelFilterAndMapToMapStream[K comparable, V any, T any](a Stream[T], fn func(t T) (K, V, bool), c int) (r MapStream[K, V]) {
|
||||
m := newMapX[K, V]()
|
||||
a.ParallelForEach(func(t T) {
|
||||
k, v, ok := fn(t)
|
||||
if ok {
|
||||
m.set(k, v)
|
||||
}
|
||||
}, c)
|
||||
var mm = map[K]V{}
|
||||
r = NewSimpleMapStream(mm)
|
||||
return
|
||||
}
|
||||
|
||||
func SliceFilterAndMapToMapStream[K comparable, V any, T any](a Stream[T], fn func(t T) (K, V, bool), isCoverPrev bool) (r MapStream[K, V]) {
|
||||
m := make(map[K]V)
|
||||
a.ForEach(func(t T) {
|
||||
k, v, ok := fn(t)
|
||||
if ok {
|
||||
_, ok = m[k]
|
||||
if isCoverPrev || !ok {
|
||||
m[k] = v
|
||||
}
|
||||
}
|
||||
})
|
||||
r.m = m
|
||||
return
|
||||
}
|
||||
|
||||
func FilterAndMapNewStream[R, T any](a Stream[T], fn func(T) (R, bool)) Stream[R] {
|
||||
return NewStream(slice.FilterAndMap(a.arr, fn))
|
||||
}
|
||||
|
||||
func ParallelMap[R, T any](a Stream[T], fn func(T) R, c int) Stream[R] {
|
||||
var x []R
|
||||
rr := safety.NewSlice(x)
|
||||
a.ParallelForEach(func(t T) {
|
||||
rr.Append(fn(t))
|
||||
}, c)
|
||||
return Stream[R]{rr.Load()}
|
||||
}
|
||||
func MapNewStream[R, T any](a Stream[T], fn func(T) R) Stream[R] {
|
||||
return NewStream(slice.Map(a.arr, fn))
|
||||
}
|
||||
|
||||
func Reduce[T any, S any](s Stream[S], fn func(S, T) T, init T) (r T) {
|
||||
return slice.Reduce(s.arr, fn, init)
|
||||
}
|
||||
|
||||
func NewStream[T any](arr []T) Stream[T] {
|
||||
return Stream[T]{arr: arr}
|
||||
}
|
||||
|
||||
type Stream[T any] struct {
|
||||
arr []T
|
||||
}
|
||||
|
||||
func (r Stream[T]) ForEach(fn func(T)) {
|
||||
for _, t := range r.arr {
|
||||
fn(t)
|
||||
}
|
||||
}
|
||||
|
||||
func (r Stream[T]) ParallelForEach(fn func(T), c int) {
|
||||
p := taskPools.NewPools(c)
|
||||
for _, t := range r.arr {
|
||||
t := t
|
||||
p.Execute(func() {
|
||||
fn(t)
|
||||
})
|
||||
}
|
||||
p.Wait()
|
||||
}
|
||||
|
||||
func (r Stream[T]) ParallelFilter(fn func(T) bool, c int) Stream[T] {
|
||||
rr := safety.NewSlice([]T{})
|
||||
r.ParallelForEach(func(t T) {
|
||||
if fn(t) {
|
||||
rr.Append(t)
|
||||
}
|
||||
}, c)
|
||||
return Stream[T]{rr.Load()}
|
||||
}
|
||||
func (r Stream[T]) Filter(fn func(T) bool) Stream[T] {
|
||||
r.arr = slice.Filter(r.arr, fn)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r Stream[T]) ParallelMap(fn func(T) T, c int) Stream[T] {
|
||||
rr := safety.NewSlice([]T{})
|
||||
r.ParallelForEach(func(t T) {
|
||||
rr.Append(fn(t))
|
||||
}, c)
|
||||
return Stream[T]{rr.Load()}
|
||||
}
|
||||
|
||||
func (r Stream[T]) Map(fn func(T) T) Stream[T] {
|
||||
r.arr = slice.Map(r.arr, fn)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r Stream[T]) Sort(fn func(i, j T) bool) Stream[T] {
|
||||
slice.SortSelf(r.arr, fn)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r Stream[T]) Len() int {
|
||||
return len(r.arr)
|
||||
}
|
||||
|
||||
func (r Stream[T]) Limit(limit, offset int) Stream[T] {
|
||||
l := len(r.arr)
|
||||
if offset >= l {
|
||||
return Stream[T]{}
|
||||
}
|
||||
ll := offset + limit
|
||||
if ll > l {
|
||||
ll = l
|
||||
}
|
||||
return Stream[T]{r.arr[offset:ll]}
|
||||
}
|
||||
|
||||
func (r Stream[T]) Reverse() Stream[T] {
|
||||
slice.ReverseSelf(r.arr)
|
||||
return r
|
||||
}
|
||||
|
||||
func (r Stream[T]) Result() []T {
|
||||
return r.arr
|
||||
}
|
|
@ -9,7 +9,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
var s = NewSimpleSliceStream(number.Range(1, 10, 1))
|
||||
var s = NewStream(number.Range(1, 10, 1))
|
||||
|
||||
func TestSimpleSliceStream_Filter(t *testing.T) {
|
||||
type args[T int] struct {
|
||||
|
@ -17,9 +17,9 @@ func TestSimpleSliceStream_Filter(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args[T]
|
||||
want SimpleSliceStream[T]
|
||||
want Stream[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ func TestSimpleSliceStream_Filter(t *testing.T) {
|
|||
return
|
||||
},
|
||||
},
|
||||
want: SimpleSliceStream[int]{number.Range(6, 10, 1)},
|
||||
want: Stream[int]{number.Range(6, 10, 1)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -51,7 +51,7 @@ func TestSimpleSliceStream_ForEach(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
|
@ -79,9 +79,9 @@ func TestSimpleSliceStream_Limit(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args
|
||||
want SimpleSliceStream[T]
|
||||
want Stream[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ func TestSimpleSliceStream_Limit(t *testing.T) {
|
|||
limit: 3,
|
||||
offset: 5,
|
||||
},
|
||||
want: SimpleSliceStream[int]{number.Range(6, 8, 1)},
|
||||
want: Stream[int]{number.Range(6, 8, 1)},
|
||||
},
|
||||
{
|
||||
name: "t2",
|
||||
|
@ -100,7 +100,7 @@ func TestSimpleSliceStream_Limit(t *testing.T) {
|
|||
limit: 3,
|
||||
offset: 9,
|
||||
},
|
||||
want: SimpleSliceStream[int]{number.Range(10, 10, 1)},
|
||||
want: Stream[int]{number.Range(10, 10, 1)},
|
||||
},
|
||||
{
|
||||
name: "t3",
|
||||
|
@ -109,7 +109,7 @@ func TestSimpleSliceStream_Limit(t *testing.T) {
|
|||
limit: 3,
|
||||
offset: 11,
|
||||
},
|
||||
want: SimpleSliceStream[int]{},
|
||||
want: Stream[int]{},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -127,9 +127,9 @@ func TestSimpleSliceStream_Map(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args[T]
|
||||
want SimpleSliceStream[T]
|
||||
want Stream[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
{
|
||||
|
@ -140,13 +140,13 @@ func TestSimpleSliceStream_Map(t *testing.T) {
|
|||
return t * 2
|
||||
},
|
||||
},
|
||||
want: SimpleSliceStream[int]{number.Range(2, 20, 2)},
|
||||
want: Stream[int]{number.Range(2, 20, 2)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.r.Map(tt.args.fn); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("Map() = %v, want %v", got, tt.want)
|
||||
t.Errorf("MapNewStream() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func TestSimpleSliceStream_Map(t *testing.T) {
|
|||
func TestSimpleSliceStream_Result(t *testing.T) {
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
want []T
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
|
@ -180,9 +180,9 @@ func TestSimpleSliceStream_Sort(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args[T]
|
||||
want SimpleSliceStream[T]
|
||||
want Stream[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
{
|
||||
|
@ -193,7 +193,7 @@ func TestSimpleSliceStream_Sort(t *testing.T) {
|
|||
return i > j
|
||||
},
|
||||
},
|
||||
want: SimpleSliceStream[int]{number.Range(10, 1, -1)},
|
||||
want: Stream[int]{number.Range(10, 1, -1)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -212,7 +212,7 @@ func TestSimpleSliceStream_parallelForEach(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
|
@ -241,9 +241,9 @@ func TestSimpleSliceStream_ParallelFilter(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args[T]
|
||||
want SimpleSliceStream[T]
|
||||
want Stream[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
{
|
||||
|
@ -255,7 +255,7 @@ func TestSimpleSliceStream_ParallelFilter(t *testing.T) {
|
|||
},
|
||||
c: 6,
|
||||
},
|
||||
want: SimpleSliceStream[int]{number.Range(4, 10, 1)},
|
||||
want: Stream[int]{number.Range(4, 10, 1)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -276,9 +276,9 @@ func TestSimpleSliceStream_ParallelMap(t *testing.T) {
|
|||
}
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
args args[T]
|
||||
want SimpleSliceStream[T]
|
||||
want Stream[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
{
|
||||
|
@ -290,7 +290,7 @@ func TestSimpleSliceStream_ParallelMap(t *testing.T) {
|
|||
},
|
||||
c: 6,
|
||||
},
|
||||
want: SimpleSliceStream[int]{number.Range(2, 20, 2)},
|
||||
want: Stream[int]{number.Range(2, 20, 2)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -298,7 +298,7 @@ func TestSimpleSliceStream_ParallelMap(t *testing.T) {
|
|||
if got := tt.r.ParallelMap(tt.args.fn, tt.args.c).Sort(func(i, j int) bool {
|
||||
return i < j
|
||||
}); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SimpleParallelMap() = %v, want %v", got, tt.want)
|
||||
t.Errorf("ParallelMap() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ func TestSimpleSliceStream_ParallelMap(t *testing.T) {
|
|||
|
||||
func TestReduce(t *testing.T) {
|
||||
type args[S, T int] struct {
|
||||
s SimpleSliceStream[S]
|
||||
s Stream[S]
|
||||
fn func(S, T) T
|
||||
init T
|
||||
}
|
||||
|
@ -339,14 +339,14 @@ func TestReduce(t *testing.T) {
|
|||
func TestSimpleSliceStream_Reverse(t *testing.T) {
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
want SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
want Stream[T]
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
{
|
||||
name: "t1",
|
||||
r: NewSimpleSliceStream(number.Range(1, 10, 1)),
|
||||
want: SimpleSliceStream[int]{number.Range(10, 1, -1)},
|
||||
r: NewStream(number.Range(1, 10, 1)),
|
||||
want: Stream[int]{number.Range(10, 1, -1)},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
@ -362,30 +362,30 @@ var x = number.Range(1, 100000, 1)
|
|||
|
||||
func TestSimpleStreamMap(t *testing.T) {
|
||||
type args[T int, R string] struct {
|
||||
a SimpleSliceStream[T]
|
||||
a Stream[T]
|
||||
fn func(T) R
|
||||
}
|
||||
type testCase[T int, R string] struct {
|
||||
name string
|
||||
args args[T, R]
|
||||
want SimpleSliceStream[R]
|
||||
want Stream[R]
|
||||
}
|
||||
tests := []testCase[int, string]{
|
||||
{
|
||||
name: "t1",
|
||||
args: args[int, string]{
|
||||
a: NewSimpleSliceStream(x),
|
||||
a: NewStream(x),
|
||||
fn: strconv.Itoa,
|
||||
},
|
||||
want: SimpleSliceStream[string]{
|
||||
want: Stream[string]{
|
||||
slice.Map(x, strconv.Itoa),
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := SimpleStreamMap(tt.args.a, tt.args.fn); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SimpleStreamMap() = %v, want %v", got, tt.want)
|
||||
if got := MapNewStream(tt.args.a, tt.args.fn); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("MapNewStream() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -393,36 +393,36 @@ func TestSimpleStreamMap(t *testing.T) {
|
|||
|
||||
func TestSimpleParallelMap(t *testing.T) {
|
||||
type args[T string, R int] struct {
|
||||
a SimpleSliceStream[string]
|
||||
a Stream[string]
|
||||
fn func(T) R
|
||||
c int
|
||||
}
|
||||
type testCase[T string, R int] struct {
|
||||
name string
|
||||
args args[T, R]
|
||||
want SimpleSliceStream[R]
|
||||
want Stream[R]
|
||||
}
|
||||
|
||||
tests := []testCase[string, int]{
|
||||
{
|
||||
name: "t1",
|
||||
args: args[string, int]{
|
||||
a: NewSimpleSliceStream(slice.Map(x, strconv.Itoa)),
|
||||
a: NewStream(slice.Map(x, strconv.Itoa)),
|
||||
fn: func(s string) int {
|
||||
i, _ := strconv.Atoi(s)
|
||||
return i
|
||||
},
|
||||
c: 6,
|
||||
},
|
||||
want: NewSimpleSliceStream(x),
|
||||
want: NewStream(x),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := SimpleParallelMap(tt.args.a, tt.args.fn, tt.args.c).Sort(func(i, j int) bool {
|
||||
if got := ParallelMap(tt.args.a, tt.args.fn, tt.args.c).Sort(func(i, j int) bool {
|
||||
return i < j
|
||||
}); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SimpleParallelMap() = %v, want %v", got, tt.want)
|
||||
t.Errorf("ParallelMap() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -430,20 +430,20 @@ func TestSimpleParallelMap(t *testing.T) {
|
|||
|
||||
func TestSimpleParallelFilterAndMap(t *testing.T) {
|
||||
type args[T string, R int] struct {
|
||||
a SimpleSliceStream[string]
|
||||
a Stream[string]
|
||||
fn func(T) (R, bool)
|
||||
c int
|
||||
}
|
||||
type testCase[T string, R int] struct {
|
||||
name string
|
||||
args args[T, R]
|
||||
want SimpleSliceStream[R]
|
||||
want Stream[R]
|
||||
}
|
||||
tests := []testCase[string, int]{
|
||||
{
|
||||
name: "t1",
|
||||
args: args[string, int]{
|
||||
a: NewSimpleSliceStream(slice.Map(x, strconv.Itoa)),
|
||||
a: NewStream(slice.Map(x, strconv.Itoa)),
|
||||
fn: func(s string) (int, bool) {
|
||||
i, _ := strconv.Atoi(s)
|
||||
if i > 50000 {
|
||||
|
@ -453,15 +453,15 @@ func TestSimpleParallelFilterAndMap(t *testing.T) {
|
|||
},
|
||||
c: 6,
|
||||
},
|
||||
want: NewSimpleSliceStream(x[50000:]),
|
||||
want: NewStream(x[50000:]),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := SimpleParallelFilterAndMap(tt.args.a, tt.args.fn, tt.args.c).Sort(func(i, j int) bool {
|
||||
if got := ParallelFilterAndMap(tt.args.a, tt.args.fn, tt.args.c).Sort(func(i, j int) bool {
|
||||
return i < j
|
||||
}); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SimpleParallelFilterAndMap() = %v, want %v", got, tt.want)
|
||||
t.Errorf("ParallelFilterAndMap() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -469,19 +469,19 @@ func TestSimpleParallelFilterAndMap(t *testing.T) {
|
|||
|
||||
func TestSimpleStreamFilterAndMap(t *testing.T) {
|
||||
type args[T string, R int] struct {
|
||||
a SimpleSliceStream[T]
|
||||
a Stream[T]
|
||||
fn func(T) (R, bool)
|
||||
}
|
||||
type testCase[T any, R any] struct {
|
||||
name string
|
||||
args args[string, int]
|
||||
want SimpleSliceStream[R]
|
||||
want Stream[R]
|
||||
}
|
||||
tests := []testCase[string, int]{
|
||||
{
|
||||
name: "t1",
|
||||
args: args[string, int]{
|
||||
a: NewSimpleSliceStream(slice.Map(x, strconv.Itoa)),
|
||||
a: NewStream(slice.Map(x, strconv.Itoa)),
|
||||
fn: func(s string) (int, bool) {
|
||||
i, _ := strconv.Atoi(s)
|
||||
if i > 50000 {
|
||||
|
@ -490,13 +490,13 @@ func TestSimpleStreamFilterAndMap(t *testing.T) {
|
|||
return 0, false
|
||||
},
|
||||
},
|
||||
want: NewSimpleSliceStream(x[50000:]),
|
||||
want: NewStream(x[50000:]),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := SimpleStreamFilterAndMap(tt.args.a, tt.args.fn); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SimpleStreamFilterAndMap() = %v, want %v", got, tt.want)
|
||||
if got := FilterAndMapNewStream(tt.args.a, tt.args.fn); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("FilterAndMapNewStream() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ func TestSimpleStreamFilterAndMap(t *testing.T) {
|
|||
func TestSimpleSliceStream_Len(t *testing.T) {
|
||||
type testCase[T int] struct {
|
||||
name string
|
||||
r SimpleSliceStream[T]
|
||||
r Stream[T]
|
||||
want int
|
||||
}
|
||||
tests := []testCase[int]{
|
||||
|
@ -526,20 +526,20 @@ func TestSimpleSliceStream_Len(t *testing.T) {
|
|||
|
||||
func TestSimpleParallelFilterAndMapToMap(t *testing.T) {
|
||||
type args[T int, K int, V int] struct {
|
||||
a SimpleSliceStream[V]
|
||||
a Stream[V]
|
||||
fn func(t T) (K, V, bool)
|
||||
c int
|
||||
}
|
||||
type testCase[T int, K int, V int] struct {
|
||||
name string
|
||||
args args[T, K, V]
|
||||
wantR SimpleMapStream[K, V]
|
||||
wantR MapStream[K, V]
|
||||
}
|
||||
tests := []testCase[int, int, int]{
|
||||
{
|
||||
name: "t1",
|
||||
args: args[int, int, int]{
|
||||
a: NewSimpleSliceStream(x),
|
||||
a: NewStream(x),
|
||||
fn: func(v int) (int, int, bool) {
|
||||
if v >= 50000 {
|
||||
return v, v, true
|
||||
|
@ -555,8 +555,8 @@ func TestSimpleParallelFilterAndMapToMap(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotR := SimpleParallelFilterAndMapToMap(tt.args.a, tt.args.fn, tt.args.c); !reflect.DeepEqual(gotR, tt.wantR) {
|
||||
t.Errorf("SimpleParallelFilterAndMapToMap() = %v, want %v", gotR, tt.wantR)
|
||||
if gotR := ParallelFilterAndMapToMapStream(tt.args.a, tt.args.fn, tt.args.c); !reflect.DeepEqual(gotR, tt.wantR) {
|
||||
t.Errorf("ParallelFilterAndMapToMapStream() = %v, want %v", gotR, tt.wantR)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -564,20 +564,20 @@ func TestSimpleParallelFilterAndMapToMap(t *testing.T) {
|
|||
|
||||
func TestSimpleSliceFilterAndMapToMap(t *testing.T) {
|
||||
type args[T int, K int, V int] struct {
|
||||
a SimpleSliceStream[T]
|
||||
a Stream[T]
|
||||
fn func(t T) (K, V, bool)
|
||||
isCoverPrev bool
|
||||
}
|
||||
type testCase[T int, K int, V int] struct {
|
||||
name string
|
||||
args args[T, K, V]
|
||||
wantR SimpleMapStream[K, V]
|
||||
wantR MapStream[K, V]
|
||||
}
|
||||
tests := []testCase[int, int, int]{
|
||||
{
|
||||
name: "t1",
|
||||
args: args[int, int, int]{
|
||||
a: NewSimpleSliceStream(number.Range(1, 10, 1)),
|
||||
a: NewStream(number.Range(1, 10, 1)),
|
||||
fn: func(i int) (int, int, bool) {
|
||||
if i > 6 {
|
||||
return i, i, true
|
||||
|
@ -592,8 +592,8 @@ func TestSimpleSliceFilterAndMapToMap(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if gotR := SimpleSliceFilterAndMapToMap(tt.args.a, tt.args.fn, tt.args.isCoverPrev); !reflect.DeepEqual(gotR, tt.wantR) {
|
||||
t.Errorf("SimpleSliceFilterAndMapToMap() = %v, want %v", gotR, tt.wantR)
|
||||
if gotR := SliceFilterAndMapToMapStream(tt.args.a, tt.args.fn, tt.args.isCoverPrev); !reflect.DeepEqual(gotR, tt.wantR) {
|
||||
t.Errorf("SliceFilterAndMapToMapStream() = %v, want %v", gotR, tt.wantR)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user