mirror of
https://github.com/samber/lo.git
synced 2025-10-27 18:00:40 +08:00
remove unnecessary explicit typeparams (#134)
This commit is contained in:
@@ -27,7 +27,7 @@ func BenchmarkMap(b *testing.B) {
|
|||||||
|
|
||||||
b.Run("lo.Map", func(b *testing.B) {
|
b.Run("lo.Map", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
_ = Map[int64](arr, func(x int64, i int) string {
|
_ = Map(arr, func(x int64, i int) string {
|
||||||
return strconv.FormatInt(x, 10)
|
return strconv.FormatInt(x, 10)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func BenchmarkMap(b *testing.B) {
|
|||||||
|
|
||||||
b.Run("lop.Map", func(b *testing.B) {
|
b.Run("lop.Map", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
_ = lop.Map[int64](arr, func(x int64, i int) string {
|
_ = lop.Map(arr, func(x int64, i int) string {
|
||||||
return strconv.FormatInt(x, 10)
|
return strconv.FormatInt(x, 10)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
func TestTernary(t *testing.T) {
|
func TestTernary(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Ternary[string](true, "a", "b")
|
result1 := Ternary(true, "a", "b")
|
||||||
result2 := Ternary[string](false, "a", "b")
|
result2 := Ternary(false, "a", "b")
|
||||||
|
|
||||||
is.Equal(result1, "a")
|
is.Equal(result1, "a")
|
||||||
is.Equal(result2, "b")
|
is.Equal(result2, "b")
|
||||||
@@ -19,10 +19,10 @@ func TestTernary(t *testing.T) {
|
|||||||
func TestIfElse(t *testing.T) {
|
func TestIfElse(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := If[int](true, 1).ElseIf(false, 2).Else(3)
|
result1 := If(true, 1).ElseIf(false, 2).Else(3)
|
||||||
result2 := If[int](true, 1).ElseIf(true, 2).Else(3)
|
result2 := If(true, 1).ElseIf(true, 2).Else(3)
|
||||||
result3 := If[int](false, 1).ElseIf(true, 2).Else(3)
|
result3 := If(false, 1).ElseIf(true, 2).Else(3)
|
||||||
result4 := If[int](false, 1).ElseIf(false, 2).Else(3)
|
result4 := If(false, 1).ElseIf(false, 2).Else(3)
|
||||||
|
|
||||||
is.Equal(result1, 1)
|
is.Equal(result1, 1)
|
||||||
is.Equal(result2, 1)
|
is.Equal(result2, 1)
|
||||||
@@ -33,10 +33,10 @@ func TestIfElse(t *testing.T) {
|
|||||||
func TestIfFElseF(t *testing.T) {
|
func TestIfFElseF(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := IfF[int](true, func() int { return 1 }).ElseIfF(false, func() int { return 2 }).ElseF(func() int { return 3 })
|
result1 := IfF(true, func() int { return 1 }).ElseIfF(false, func() int { return 2 }).ElseF(func() int { return 3 })
|
||||||
result2 := IfF[int](true, func() int { return 1 }).ElseIfF(true, func() int { return 2 }).ElseF(func() int { return 3 })
|
result2 := IfF(true, func() int { return 1 }).ElseIfF(true, func() int { return 2 }).ElseF(func() int { return 3 })
|
||||||
result3 := IfF[int](false, func() int { return 1 }).ElseIfF(true, func() int { return 2 }).ElseF(func() int { return 3 })
|
result3 := IfF(false, func() int { return 1 }).ElseIfF(true, func() int { return 2 }).ElseF(func() int { return 3 })
|
||||||
result4 := IfF[int](false, func() int { return 1 }).ElseIfF(false, func() int { return 2 }).ElseF(func() int { return 3 })
|
result4 := IfF(false, func() int { return 1 }).ElseIfF(false, func() int { return 2 }).ElseF(func() int { return 3 })
|
||||||
|
|
||||||
is.Equal(result1, 1)
|
is.Equal(result1, 1)
|
||||||
is.Equal(result2, 1)
|
is.Equal(result2, 1)
|
||||||
|
|||||||
72
find_test.go
72
find_test.go
@@ -13,8 +13,8 @@ import (
|
|||||||
func TestIndexOf(t *testing.T) {
|
func TestIndexOf(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := IndexOf[int]([]int{0, 1, 2, 1, 2, 3}, 2)
|
result1 := IndexOf([]int{0, 1, 2, 1, 2, 3}, 2)
|
||||||
result2 := IndexOf[int]([]int{0, 1, 2, 1, 2, 3}, 6)
|
result2 := IndexOf([]int{0, 1, 2, 1, 2, 3}, 6)
|
||||||
|
|
||||||
is.Equal(result1, 2)
|
is.Equal(result1, 2)
|
||||||
is.Equal(result2, -1)
|
is.Equal(result2, -1)
|
||||||
@@ -23,8 +23,8 @@ func TestIndexOf(t *testing.T) {
|
|||||||
func TestLastIndexOf(t *testing.T) {
|
func TestLastIndexOf(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := LastIndexOf[int]([]int{0, 1, 2, 1, 2, 3}, 2)
|
result1 := LastIndexOf([]int{0, 1, 2, 1, 2, 3}, 2)
|
||||||
result2 := LastIndexOf[int]([]int{0, 1, 2, 1, 2, 3}, 6)
|
result2 := LastIndexOf([]int{0, 1, 2, 1, 2, 3}, 6)
|
||||||
|
|
||||||
is.Equal(result1, 4)
|
is.Equal(result1, 4)
|
||||||
is.Equal(result2, -1)
|
is.Equal(result2, -1)
|
||||||
@@ -33,10 +33,10 @@ func TestLastIndexOf(t *testing.T) {
|
|||||||
func TestFind(t *testing.T) {
|
func TestFind(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1, ok1 := Find[string]([]string{"a", "b", "c", "d"}, func(i string) bool {
|
result1, ok1 := Find([]string{"a", "b", "c", "d"}, func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
result2, ok2 := Find[string]([]string{"foobar"}, func(i string) bool {
|
result2, ok2 := Find([]string{"foobar"}, func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -49,10 +49,10 @@ func TestFind(t *testing.T) {
|
|||||||
func TestFindIndexOf(t *testing.T) {
|
func TestFindIndexOf(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
item1, index1, ok1 := FindIndexOf[string]([]string{"a", "b", "c", "d", "b"}, func(i string) bool {
|
item1, index1, ok1 := FindIndexOf([]string{"a", "b", "c", "d", "b"}, func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
item2, index2, ok2 := FindIndexOf[string]([]string{"foobar"}, func(i string) bool {
|
item2, index2, ok2 := FindIndexOf([]string{"foobar"}, func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -67,10 +67,10 @@ func TestFindIndexOf(t *testing.T) {
|
|||||||
func TestFindLastIndexOf(t *testing.T) {
|
func TestFindLastIndexOf(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
item1, index1, ok1 := FindLastIndexOf[string]([]string{"a", "b", "c", "d", "b"}, func(i string) bool {
|
item1, index1, ok1 := FindLastIndexOf([]string{"a", "b", "c", "d", "b"}, func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
item2, index2, ok2 := FindLastIndexOf[string]([]string{"foobar"}, func(i string) bool {
|
item2, index2, ok2 := FindLastIndexOf([]string{"foobar"}, func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -85,10 +85,10 @@ func TestFindLastIndexOf(t *testing.T) {
|
|||||||
func TestFindOrElse(t *testing.T) {
|
func TestFindOrElse(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := FindOrElse[string]([]string{"a", "b", "c", "d"}, "x", func(i string) bool {
|
result1 := FindOrElse([]string{"a", "b", "c", "d"}, "x", func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
result2 := FindOrElse[string]([]string{"foobar"}, "x", func(i string) bool {
|
result2 := FindOrElse([]string{"foobar"}, "x", func(i string) bool {
|
||||||
return i == "b"
|
return i == "b"
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -99,9 +99,9 @@ func TestFindOrElse(t *testing.T) {
|
|||||||
func TestMin(t *testing.T) {
|
func TestMin(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Min[int]([]int{1, 2, 3})
|
result1 := Min([]int{1, 2, 3})
|
||||||
result2 := Min[int]([]int{3, 2, 1})
|
result2 := Min([]int{3, 2, 1})
|
||||||
result3 := Min[int]([]int{})
|
result3 := Min([]int{})
|
||||||
|
|
||||||
is.Equal(result1, 1)
|
is.Equal(result1, 1)
|
||||||
is.Equal(result2, 1)
|
is.Equal(result2, 1)
|
||||||
@@ -111,13 +111,13 @@ func TestMin(t *testing.T) {
|
|||||||
func TestMinBy(t *testing.T) {
|
func TestMinBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := MinBy[string]([]string{"s1", "string2", "s3"}, func(item string, min string) bool {
|
result1 := MinBy([]string{"s1", "string2", "s3"}, func(item string, min string) bool {
|
||||||
return len(item) < len(min)
|
return len(item) < len(min)
|
||||||
})
|
})
|
||||||
result2 := MinBy[string]([]string{"string1", "string2", "s3"}, func(item string, min string) bool {
|
result2 := MinBy([]string{"string1", "string2", "s3"}, func(item string, min string) bool {
|
||||||
return len(item) < len(min)
|
return len(item) < len(min)
|
||||||
})
|
})
|
||||||
result3 := MinBy[string]([]string{}, func(item string, min string) bool {
|
result3 := MinBy([]string{}, func(item string, min string) bool {
|
||||||
return len(item) < len(min)
|
return len(item) < len(min)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -129,9 +129,9 @@ func TestMinBy(t *testing.T) {
|
|||||||
func TestMax(t *testing.T) {
|
func TestMax(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Max[int]([]int{1, 2, 3})
|
result1 := Max([]int{1, 2, 3})
|
||||||
result2 := Max[int]([]int{3, 2, 1})
|
result2 := Max([]int{3, 2, 1})
|
||||||
result3 := Max[int]([]int{})
|
result3 := Max([]int{})
|
||||||
|
|
||||||
is.Equal(result1, 3)
|
is.Equal(result1, 3)
|
||||||
is.Equal(result2, 3)
|
is.Equal(result2, 3)
|
||||||
@@ -141,13 +141,13 @@ func TestMax(t *testing.T) {
|
|||||||
func TestMaxBy(t *testing.T) {
|
func TestMaxBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := MaxBy[string]([]string{"s1", "string2", "s3"}, func(item string, max string) bool {
|
result1 := MaxBy([]string{"s1", "string2", "s3"}, func(item string, max string) bool {
|
||||||
return len(item) > len(max)
|
return len(item) > len(max)
|
||||||
})
|
})
|
||||||
result2 := MaxBy[string]([]string{"string1", "string2", "s3"}, func(item string, max string) bool {
|
result2 := MaxBy([]string{"string1", "string2", "s3"}, func(item string, max string) bool {
|
||||||
return len(item) > len(max)
|
return len(item) > len(max)
|
||||||
})
|
})
|
||||||
result3 := MaxBy[string]([]string{}, func(item string, max string) bool {
|
result3 := MaxBy([]string{}, func(item string, max string) bool {
|
||||||
return len(item) > len(max)
|
return len(item) > len(max)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -159,8 +159,8 @@ func TestMaxBy(t *testing.T) {
|
|||||||
func TestLast(t *testing.T) {
|
func TestLast(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1, err1 := Last[int]([]int{1, 2, 3})
|
result1, err1 := Last([]int{1, 2, 3})
|
||||||
result2, err2 := Last[int]([]int{})
|
result2, err2 := Last([]int{})
|
||||||
|
|
||||||
is.Equal(result1, 3)
|
is.Equal(result1, 3)
|
||||||
is.Equal(err1, nil)
|
is.Equal(err1, nil)
|
||||||
@@ -171,11 +171,11 @@ func TestLast(t *testing.T) {
|
|||||||
func TestNth(t *testing.T) {
|
func TestNth(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1, err1 := Nth[int]([]int{0, 1, 2, 3}, 2)
|
result1, err1 := Nth([]int{0, 1, 2, 3}, 2)
|
||||||
result2, err2 := Nth[int]([]int{0, 1, 2, 3}, -2)
|
result2, err2 := Nth([]int{0, 1, 2, 3}, -2)
|
||||||
result3, err3 := Nth[int]([]int{0, 1, 2, 3}, 42)
|
result3, err3 := Nth([]int{0, 1, 2, 3}, 42)
|
||||||
result4, err4 := Nth[int]([]int{}, 0)
|
result4, err4 := Nth([]int{}, 0)
|
||||||
result5, err5 := Nth[int]([]int{42}, 0)
|
result5, err5 := Nth([]int{42}, 0)
|
||||||
|
|
||||||
is.Equal(result1, 2)
|
is.Equal(result1, 2)
|
||||||
is.Equal(err1, nil)
|
is.Equal(err1, nil)
|
||||||
@@ -194,10 +194,10 @@ func TestSample(t *testing.T) {
|
|||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
result1 := Sample[string]([]string{"a", "b", "c"})
|
result1 := Sample([]string{"a", "b", "c"})
|
||||||
result2 := Sample[string]([]string{})
|
result2 := Sample([]string{})
|
||||||
|
|
||||||
is.True(Contains[string]([]string{"a", "b", "c"}, result1))
|
is.True(Contains([]string{"a", "b", "c"}, result1))
|
||||||
is.Equal(result2, "")
|
is.Equal(result2, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,8 +206,8 @@ func TestSamples(t *testing.T) {
|
|||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
result1 := Samples[string]([]string{"a", "b", "c"}, 3)
|
result1 := Samples([]string{"a", "b", "c"}, 3)
|
||||||
result2 := Samples[string]([]string{}, 3)
|
result2 := Samples([]string{}, 3)
|
||||||
|
|
||||||
sort.Strings(result1)
|
sort.Strings(result1)
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
func TestContains(t *testing.T) {
|
func TestContains(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Contains[int]([]int{0, 1, 2, 3, 4, 5}, 5)
|
result1 := Contains([]int{0, 1, 2, 3, 4, 5}, 5)
|
||||||
result2 := Contains[int]([]int{0, 1, 2, 3, 4, 5}, 6)
|
result2 := Contains([]int{0, 1, 2, 3, 4, 5}, 6)
|
||||||
|
|
||||||
is.Equal(result1, true)
|
is.Equal(result1, true)
|
||||||
is.Equal(result2, false)
|
is.Equal(result2, false)
|
||||||
@@ -24,13 +24,13 @@ func TestContainsBy(t *testing.T) {
|
|||||||
B string
|
B string
|
||||||
}
|
}
|
||||||
|
|
||||||
a1 := []a{a{A: 1, B: "1"}, a{A: 2, B: "2"}, a{A: 3, B: "3"}}
|
a1 := []a{{A: 1, B: "1"}, {A: 2, B: "2"}, {A: 3, B: "3"}}
|
||||||
result1 := ContainsBy[a](a1, func(t a) bool { return t.A == 1 && t.B == "2" })
|
result1 := ContainsBy(a1, func(t a) bool { return t.A == 1 && t.B == "2" })
|
||||||
result2 := ContainsBy[a](a1, func(t a) bool { return t.A == 2 && t.B == "2" })
|
result2 := ContainsBy(a1, func(t a) bool { return t.A == 2 && t.B == "2" })
|
||||||
|
|
||||||
a2 := []string{"aaa", "bbb", "ccc"}
|
a2 := []string{"aaa", "bbb", "ccc"}
|
||||||
result3 := ContainsBy[string](a2, func(t string) bool { return t == "ccc" })
|
result3 := ContainsBy(a2, func(t string) bool { return t == "ccc" })
|
||||||
result4 := ContainsBy[string](a2, func(t string) bool { return t == "ddd" })
|
result4 := ContainsBy(a2, func(t string) bool { return t == "ddd" })
|
||||||
|
|
||||||
is.Equal(result1, false)
|
is.Equal(result1, false)
|
||||||
is.Equal(result2, true)
|
is.Equal(result2, true)
|
||||||
@@ -41,10 +41,10 @@ func TestContainsBy(t *testing.T) {
|
|||||||
func TestEvery(t *testing.T) {
|
func TestEvery(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Every[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
result1 := Every([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
||||||
result2 := Every[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
result2 := Every([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
||||||
result3 := Every[int]([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
result3 := Every([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
||||||
result4 := Every[int]([]int{0, 1, 2, 3, 4, 5}, []int{})
|
result4 := Every([]int{0, 1, 2, 3, 4, 5}, []int{})
|
||||||
|
|
||||||
is.True(result1)
|
is.True(result1)
|
||||||
is.False(result2)
|
is.False(result2)
|
||||||
@@ -55,25 +55,25 @@ func TestEvery(t *testing.T) {
|
|||||||
func TestEveryBy(t *testing.T) {
|
func TestEveryBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := EveryBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result1 := EveryBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 5
|
return x < 5
|
||||||
})
|
})
|
||||||
|
|
||||||
is.True(result1)
|
is.True(result1)
|
||||||
|
|
||||||
result2 := EveryBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result2 := EveryBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 3
|
return x < 3
|
||||||
})
|
})
|
||||||
|
|
||||||
is.False(result2)
|
is.False(result2)
|
||||||
|
|
||||||
result3 := EveryBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result3 := EveryBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 0
|
return x < 0
|
||||||
})
|
})
|
||||||
|
|
||||||
is.False(result3)
|
is.False(result3)
|
||||||
|
|
||||||
result4 := EveryBy[int]([]int{}, func(x int) bool {
|
result4 := EveryBy([]int{}, func(x int) bool {
|
||||||
return x < 5
|
return x < 5
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -83,10 +83,10 @@ func TestEveryBy(t *testing.T) {
|
|||||||
func TestSome(t *testing.T) {
|
func TestSome(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Some[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
result1 := Some([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
||||||
result2 := Some[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
result2 := Some([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
||||||
result3 := Some[int]([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
result3 := Some([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
||||||
result4 := Some[int]([]int{0, 1, 2, 3, 4, 5}, []int{})
|
result4 := Some([]int{0, 1, 2, 3, 4, 5}, []int{})
|
||||||
|
|
||||||
is.True(result1)
|
is.True(result1)
|
||||||
is.True(result2)
|
is.True(result2)
|
||||||
@@ -97,25 +97,25 @@ func TestSome(t *testing.T) {
|
|||||||
func TestSomeBy(t *testing.T) {
|
func TestSomeBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := SomeBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result1 := SomeBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 5
|
return x < 5
|
||||||
})
|
})
|
||||||
|
|
||||||
is.True(result1)
|
is.True(result1)
|
||||||
|
|
||||||
result2 := SomeBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result2 := SomeBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 3
|
return x < 3
|
||||||
})
|
})
|
||||||
|
|
||||||
is.True(result2)
|
is.True(result2)
|
||||||
|
|
||||||
result3 := SomeBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result3 := SomeBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 0
|
return x < 0
|
||||||
})
|
})
|
||||||
|
|
||||||
is.False(result3)
|
is.False(result3)
|
||||||
|
|
||||||
result4 := SomeBy[int]([]int{}, func(x int) bool {
|
result4 := SomeBy([]int{}, func(x int) bool {
|
||||||
return x < 5
|
return x < 5
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -125,10 +125,10 @@ func TestSomeBy(t *testing.T) {
|
|||||||
func TestNone(t *testing.T) {
|
func TestNone(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := None[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
result1 := None([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
||||||
result2 := None[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
result2 := None([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
||||||
result3 := None[int]([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
result3 := None([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
||||||
result4 := None[int]([]int{0, 1, 2, 3, 4, 5}, []int{})
|
result4 := None([]int{0, 1, 2, 3, 4, 5}, []int{})
|
||||||
|
|
||||||
is.False(result1)
|
is.False(result1)
|
||||||
is.False(result2)
|
is.False(result2)
|
||||||
@@ -139,25 +139,25 @@ func TestNone(t *testing.T) {
|
|||||||
func TestNoneBy(t *testing.T) {
|
func TestNoneBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := NoneBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result1 := NoneBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 5
|
return x < 5
|
||||||
})
|
})
|
||||||
|
|
||||||
is.False(result1)
|
is.False(result1)
|
||||||
|
|
||||||
result2 := NoneBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result2 := NoneBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 3
|
return x < 3
|
||||||
})
|
})
|
||||||
|
|
||||||
is.False(result2)
|
is.False(result2)
|
||||||
|
|
||||||
result3 := NoneBy[int]([]int{1, 2, 3, 4}, func(x int) bool {
|
result3 := NoneBy([]int{1, 2, 3, 4}, func(x int) bool {
|
||||||
return x < 0
|
return x < 0
|
||||||
})
|
})
|
||||||
|
|
||||||
is.True(result3)
|
is.True(result3)
|
||||||
|
|
||||||
result4 := NoneBy[int]([]int{}, func(x int) bool {
|
result4 := NoneBy([]int{}, func(x int) bool {
|
||||||
return x < 5
|
return x < 5
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -167,11 +167,11 @@ func TestNoneBy(t *testing.T) {
|
|||||||
func TestIntersect(t *testing.T) {
|
func TestIntersect(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Intersect[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
result1 := Intersect([]int{0, 1, 2, 3, 4, 5}, []int{0, 2})
|
||||||
result2 := Intersect[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
result2 := Intersect([]int{0, 1, 2, 3, 4, 5}, []int{0, 6})
|
||||||
result3 := Intersect[int]([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
result3 := Intersect([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
|
||||||
result4 := Intersect[int]([]int{0, 6}, []int{0, 1, 2, 3, 4, 5})
|
result4 := Intersect([]int{0, 6}, []int{0, 1, 2, 3, 4, 5})
|
||||||
result5 := Intersect[int]([]int{0, 6, 0}, []int{0, 1, 2, 3, 4, 5})
|
result5 := Intersect([]int{0, 6, 0}, []int{0, 1, 2, 3, 4, 5})
|
||||||
|
|
||||||
is.Equal(result1, []int{0, 2})
|
is.Equal(result1, []int{0, 2})
|
||||||
is.Equal(result2, []int{0})
|
is.Equal(result2, []int{0})
|
||||||
@@ -183,26 +183,26 @@ func TestIntersect(t *testing.T) {
|
|||||||
func TestDifference(t *testing.T) {
|
func TestDifference(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
left1, right1 := Difference[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 2, 6})
|
left1, right1 := Difference([]int{0, 1, 2, 3, 4, 5}, []int{0, 2, 6})
|
||||||
is.Equal(left1, []int{1, 3, 4, 5})
|
is.Equal(left1, []int{1, 3, 4, 5})
|
||||||
is.Equal(right1, []int{6})
|
is.Equal(right1, []int{6})
|
||||||
|
|
||||||
left2, right2 := Difference[int]([]int{1, 2, 3, 4, 5}, []int{0, 6})
|
left2, right2 := Difference([]int{1, 2, 3, 4, 5}, []int{0, 6})
|
||||||
is.Equal(left2, []int{1, 2, 3, 4, 5})
|
is.Equal(left2, []int{1, 2, 3, 4, 5})
|
||||||
is.Equal(right2, []int{0, 6})
|
is.Equal(right2, []int{0, 6})
|
||||||
|
|
||||||
left3, right3 := Difference[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 1, 2, 3, 4, 5})
|
left3, right3 := Difference([]int{0, 1, 2, 3, 4, 5}, []int{0, 1, 2, 3, 4, 5})
|
||||||
is.Equal(left3, []int{})
|
is.Equal(left3, []int{})
|
||||||
is.Equal(right3, []int{})
|
is.Equal(right3, []int{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnion(t *testing.T) {
|
func TestUnion(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
result1 := Union[int]([]int{0, 1, 2, 3, 4, 5}, []int{0, 2, 10})
|
result1 := Union([]int{0, 1, 2, 3, 4, 5}, []int{0, 2, 10})
|
||||||
result2 := Union[int]([]int{0, 1, 2, 3, 4, 5}, []int{6, 7})
|
result2 := Union([]int{0, 1, 2, 3, 4, 5}, []int{6, 7})
|
||||||
result3 := Union[int]([]int{0, 1, 2, 3, 4, 5}, []int{})
|
result3 := Union([]int{0, 1, 2, 3, 4, 5}, []int{})
|
||||||
result4 := Union[int]([]int{0, 1, 2}, []int{0, 1, 2})
|
result4 := Union([]int{0, 1, 2}, []int{0, 1, 2})
|
||||||
result5 := Union[int]([]int{}, []int{})
|
result5 := Union([]int{}, []int{})
|
||||||
is.Equal(result1, []int{0, 1, 2, 3, 4, 5, 10})
|
is.Equal(result1, []int{0, 1, 2, 3, 4, 5, 10})
|
||||||
is.Equal(result2, []int{0, 1, 2, 3, 4, 5, 6, 7})
|
is.Equal(result2, []int{0, 1, 2, 3, 4, 5, 6, 7})
|
||||||
is.Equal(result3, []int{0, 1, 2, 3, 4, 5})
|
is.Equal(result3, []int{0, 1, 2, 3, 4, 5})
|
||||||
|
|||||||
34
map_test.go
34
map_test.go
@@ -11,7 +11,7 @@ import (
|
|||||||
func TestKeys(t *testing.T) {
|
func TestKeys(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := Keys[string, int](map[string]int{"foo": 1, "bar": 2})
|
r1 := Keys(map[string]int{"foo": 1, "bar": 2})
|
||||||
sort.Strings(r1)
|
sort.Strings(r1)
|
||||||
|
|
||||||
is.Equal(r1, []string{"bar", "foo"})
|
is.Equal(r1, []string{"bar", "foo"})
|
||||||
@@ -20,7 +20,7 @@ func TestKeys(t *testing.T) {
|
|||||||
func TestValues(t *testing.T) {
|
func TestValues(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := Values[string, int](map[string]int{"foo": 1, "bar": 2})
|
r1 := Values(map[string]int{"foo": 1, "bar": 2})
|
||||||
sort.Ints(r1)
|
sort.Ints(r1)
|
||||||
|
|
||||||
is.Equal(r1, []int{1, 2})
|
is.Equal(r1, []int{1, 2})
|
||||||
@@ -29,7 +29,7 @@ func TestValues(t *testing.T) {
|
|||||||
func TestPickBy(t *testing.T) {
|
func TestPickBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := PickBy[string, int](map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(key string, value int) bool {
|
r1 := PickBy(map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(key string, value int) bool {
|
||||||
return value%2 == 1
|
return value%2 == 1
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ func TestPickBy(t *testing.T) {
|
|||||||
func TestPickByKeys(t *testing.T) {
|
func TestPickByKeys(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := PickByKeys[string, int](map[string]int{"foo": 1, "bar": 2, "baz": 3}, []string{"foo", "baz"})
|
r1 := PickByKeys(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []string{"foo", "baz"})
|
||||||
|
|
||||||
is.Equal(r1, map[string]int{"foo": 1, "baz": 3})
|
is.Equal(r1, map[string]int{"foo": 1, "baz": 3})
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ func TestPickByKeys(t *testing.T) {
|
|||||||
func TestPickByValues(t *testing.T) {
|
func TestPickByValues(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := PickByValues[string, int](map[string]int{"foo": 1, "bar": 2, "baz": 3}, []int{1, 3})
|
r1 := PickByValues(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []int{1, 3})
|
||||||
|
|
||||||
is.Equal(r1, map[string]int{"foo": 1, "baz": 3})
|
is.Equal(r1, map[string]int{"foo": 1, "baz": 3})
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ func TestPickByValues(t *testing.T) {
|
|||||||
func TestOmitBy(t *testing.T) {
|
func TestOmitBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := OmitBy[string, int](map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(key string, value int) bool {
|
r1 := OmitBy(map[string]int{"foo": 1, "bar": 2, "baz": 3}, func(key string, value int) bool {
|
||||||
return value%2 == 1
|
return value%2 == 1
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ func TestOmitBy(t *testing.T) {
|
|||||||
func TestOmitByKeys(t *testing.T) {
|
func TestOmitByKeys(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := OmitByKeys[string, int](map[string]int{"foo": 1, "bar": 2, "baz": 3}, []string{"foo", "baz"})
|
r1 := OmitByKeys(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []string{"foo", "baz"})
|
||||||
|
|
||||||
is.Equal(r1, map[string]int{"bar": 2})
|
is.Equal(r1, map[string]int{"bar": 2})
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ func TestOmitByKeys(t *testing.T) {
|
|||||||
func TestOmitByValues(t *testing.T) {
|
func TestOmitByValues(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := OmitByValues[string, int](map[string]int{"foo": 1, "bar": 2, "baz": 3}, []int{1, 3})
|
r1 := OmitByValues(map[string]int{"foo": 1, "bar": 2, "baz": 3}, []int{1, 3})
|
||||||
|
|
||||||
is.Equal(r1, map[string]int{"bar": 2})
|
is.Equal(r1, map[string]int{"bar": 2})
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ func TestOmitByValues(t *testing.T) {
|
|||||||
func TestEntries(t *testing.T) {
|
func TestEntries(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := Entries[string, int](map[string]int{"foo": 1, "bar": 2})
|
r1 := Entries(map[string]int{"foo": 1, "bar": 2})
|
||||||
|
|
||||||
sort.Slice(r1, func(i, j int) bool {
|
sort.Slice(r1, func(i, j int) bool {
|
||||||
return r1[i].Value < r1[j].Value
|
return r1[i].Value < r1[j].Value
|
||||||
@@ -101,7 +101,7 @@ func TestEntries(t *testing.T) {
|
|||||||
func TestFromEntries(t *testing.T) {
|
func TestFromEntries(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := FromEntries[string, int]([]Entry[string, int]{
|
r1 := FromEntries([]Entry[string, int]{
|
||||||
{
|
{
|
||||||
Key: "foo",
|
Key: "foo",
|
||||||
Value: 1,
|
Value: 1,
|
||||||
@@ -120,8 +120,8 @@ func TestFromEntries(t *testing.T) {
|
|||||||
func TestInvert(t *testing.T) {
|
func TestInvert(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := Invert[string, int](map[string]int{"a": 1, "b": 2})
|
r1 := Invert(map[string]int{"a": 1, "b": 2})
|
||||||
r2 := Invert[string, int](map[string]int{"a": 1, "b": 2, "c": 1})
|
r2 := Invert(map[string]int{"a": 1, "b": 2, "c": 1})
|
||||||
|
|
||||||
is.Len(r1, 2)
|
is.Len(r1, 2)
|
||||||
is.EqualValues(map[int]string{1: "a", 2: "b"}, r1)
|
is.EqualValues(map[int]string{1: "a", 2: "b"}, r1)
|
||||||
@@ -131,7 +131,7 @@ func TestInvert(t *testing.T) {
|
|||||||
func TestAssign(t *testing.T) {
|
func TestAssign(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Assign[string, int](map[string]int{"a": 1, "b": 2}, map[string]int{"b": 3, "c": 4})
|
result1 := Assign(map[string]int{"a": 1, "b": 2}, map[string]int{"b": 3, "c": 4})
|
||||||
|
|
||||||
is.Len(result1, 3)
|
is.Len(result1, 3)
|
||||||
is.Equal(result1, map[string]int{"a": 1, "b": 3, "c": 4})
|
is.Equal(result1, map[string]int{"a": 1, "b": 3, "c": 4})
|
||||||
@@ -140,10 +140,10 @@ func TestAssign(t *testing.T) {
|
|||||||
func TestMapKeys(t *testing.T) {
|
func TestMapKeys(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := MapKeys[int, int, string](map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(x int, _ int) string {
|
result1 := MapKeys(map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(x int, _ int) string {
|
||||||
return "Hello"
|
return "Hello"
|
||||||
})
|
})
|
||||||
result2 := MapKeys[int, int, string](map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(_ int, v int) string {
|
result2 := MapKeys(map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(_ int, v int) string {
|
||||||
return strconv.FormatInt(int64(v), 10)
|
return strconv.FormatInt(int64(v), 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -155,10 +155,10 @@ func TestMapKeys(t *testing.T) {
|
|||||||
func TestMapValues(t *testing.T) {
|
func TestMapValues(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := MapValues[int, int, string](map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(x int, _ int) string {
|
result1 := MapValues(map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(x int, _ int) string {
|
||||||
return "Hello"
|
return "Hello"
|
||||||
})
|
})
|
||||||
result2 := MapValues[int, int, string](map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(x int, _ int) string {
|
result2 := MapValues(map[int]int{1: 1, 2: 2, 3: 3, 4: 4}, func(x int, _ int) string {
|
||||||
return strconv.FormatInt(int64(x), 10)
|
return strconv.FormatInt(int64(x), 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
14
math_test.go
14
math_test.go
@@ -21,8 +21,8 @@ func TestRangeFrom(t *testing.T) {
|
|||||||
result1 := RangeFrom(1, 5)
|
result1 := RangeFrom(1, 5)
|
||||||
result2 := RangeFrom(-1, -5)
|
result2 := RangeFrom(-1, -5)
|
||||||
result3 := RangeFrom(10, 0)
|
result3 := RangeFrom(10, 0)
|
||||||
result4 := RangeFrom[float64](2.0, 3)
|
result4 := RangeFrom(2.0, 3)
|
||||||
result5 := RangeFrom[float64](-2.0, -3)
|
result5 := RangeFrom(-2.0, -3)
|
||||||
is.Equal(result1, []int{1, 2, 3, 4, 5})
|
is.Equal(result1, []int{1, 2, 3, 4, 5})
|
||||||
is.Equal(result2, []int{-1, -2, -3, -4, -5})
|
is.Equal(result2, []int{-1, -2, -3, -4, -5})
|
||||||
is.Equal(result3, []int{})
|
is.Equal(result3, []int{})
|
||||||
@@ -36,7 +36,7 @@ func TestRangeClose(t *testing.T) {
|
|||||||
result2 := RangeWithSteps(0, 3, -5)
|
result2 := RangeWithSteps(0, 3, -5)
|
||||||
result3 := RangeWithSteps(1, 1, 0)
|
result3 := RangeWithSteps(1, 1, 0)
|
||||||
result4 := RangeWithSteps(3, 2, 1)
|
result4 := RangeWithSteps(3, 2, 1)
|
||||||
result5 := RangeWithSteps[float64](1.0, 4.0, 2.0)
|
result5 := RangeWithSteps(1.0, 4.0, 2.0)
|
||||||
result6 := RangeWithSteps[float32](-1.0, -4.0, -1.0)
|
result6 := RangeWithSteps[float32](-1.0, -4.0, -1.0)
|
||||||
is.Equal([]int{0, 6, 12, 18}, result1)
|
is.Equal([]int{0, 6, 12, 18}, result1)
|
||||||
is.Equal([]int{}, result2)
|
is.Equal([]int{}, result2)
|
||||||
@@ -61,10 +61,10 @@ func TestClamp(t *testing.T) {
|
|||||||
func TestSumBy(t *testing.T) {
|
func TestSumBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := SumBy[float32]([]float32{2.3, 3.3, 4, 5.3}, func(n float32) float32 { return n })
|
result1 := SumBy([]float32{2.3, 3.3, 4, 5.3}, func(n float32) float32 { return n })
|
||||||
result2 := SumBy[int32]([]int32{2, 3, 4, 5}, func(n int32) int32 { return n })
|
result2 := SumBy([]int32{2, 3, 4, 5}, func(n int32) int32 { return n })
|
||||||
result3 := SumBy[uint32]([]uint32{2, 3, 4, 5}, func(n uint32) uint32 { return n })
|
result3 := SumBy([]uint32{2, 3, 4, 5}, func(n uint32) uint32 { return n })
|
||||||
result4 := SumBy[uint32]([]uint32{}, func(n uint32) uint32 { return n })
|
result4 := SumBy([]uint32{}, func(n uint32) uint32 { return n })
|
||||||
|
|
||||||
is.Equal(result1, float32(14.900001))
|
is.Equal(result1, float32(14.900001))
|
||||||
is.Equal(result2, int32(14))
|
is.Equal(result2, int32(14))
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import (
|
|||||||
func TestMap(t *testing.T) {
|
func TestMap(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Map[int, string]([]int{1, 2, 3, 4}, func(x int, _ int) string {
|
result1 := Map([]int{1, 2, 3, 4}, func(x int, _ int) string {
|
||||||
return "Hello"
|
return "Hello"
|
||||||
})
|
})
|
||||||
result2 := Map[int64, string]([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
|
result2 := Map([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
|
||||||
return strconv.FormatInt(x, 10)
|
return strconv.FormatInt(x, 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ func TestMap(t *testing.T) {
|
|||||||
func TestTimes(t *testing.T) {
|
func TestTimes(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Times[string](3, func(i int) string {
|
result1 := Times(3, func(i int) string {
|
||||||
return strconv.FormatInt(int64(i), 10)
|
return strconv.FormatInt(int64(i), 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ func TestTimes(t *testing.T) {
|
|||||||
func TestGroupBy(t *testing.T) {
|
func TestGroupBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := GroupBy[int, int]([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
|
result1 := GroupBy([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
|
||||||
return i % 3
|
return i % 3
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -51,16 +51,16 @@ func TestGroupBy(t *testing.T) {
|
|||||||
|
|
||||||
is.EqualValues(len(result1), 3)
|
is.EqualValues(len(result1), 3)
|
||||||
is.EqualValues(result1, map[int][]int{
|
is.EqualValues(result1, map[int][]int{
|
||||||
0: []int{0, 3},
|
0: {0, 3},
|
||||||
1: []int{1, 4},
|
1: {1, 4},
|
||||||
2: []int{2, 5},
|
2: {2, 5},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPartitionBy(t *testing.T) {
|
func TestPartitionBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
oddEven := func (x int) string {
|
oddEven := func(x int) string {
|
||||||
if x < 0 {
|
if x < 0 {
|
||||||
return "negative"
|
return "negative"
|
||||||
} else if x%2 == 0 {
|
} else if x%2 == 0 {
|
||||||
@@ -69,8 +69,8 @@ func TestPartitionBy(t *testing.T) {
|
|||||||
return "odd"
|
return "odd"
|
||||||
}
|
}
|
||||||
|
|
||||||
result1 := PartitionBy[int, string]([]int{-2, -1, 0, 1, 2, 3, 4, 5}, oddEven)
|
result1 := PartitionBy([]int{-2, -1, 0, 1, 2, 3, 4, 5}, oddEven)
|
||||||
result2 := PartitionBy[int, string]([]int{}, oddEven)
|
result2 := PartitionBy([]int{}, oddEven)
|
||||||
|
|
||||||
// order
|
// order
|
||||||
sort.Slice(result1, func(i, j int) bool {
|
sort.Slice(result1, func(i, j int) bool {
|
||||||
|
|||||||
2
slice.go
2
slice.go
@@ -404,5 +404,5 @@ func Replace[T comparable](collection []T, old T, new T, n int) []T {
|
|||||||
|
|
||||||
// ReplaceAll returns a copy of the slice with all non-overlapping instances of old replaced by new.
|
// ReplaceAll returns a copy of the slice with all non-overlapping instances of old replaced by new.
|
||||||
func ReplaceAll[T comparable](collection []T, old T, new T) []T {
|
func ReplaceAll[T comparable](collection []T, old T, new T) []T {
|
||||||
return Replace[T](collection, old, new, -1)
|
return Replace(collection, old, new, -1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ func (f foo) Clone() foo {
|
|||||||
func TestFilter(t *testing.T) {
|
func TestFilter(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := Filter[int]([]int{1, 2, 3, 4}, func(x int, _ int) bool {
|
r1 := Filter([]int{1, 2, 3, 4}, func(x int, _ int) bool {
|
||||||
return x%2 == 0
|
return x%2 == 0
|
||||||
})
|
})
|
||||||
|
|
||||||
is.Equal(r1, []int{2, 4})
|
is.Equal(r1, []int{2, 4})
|
||||||
|
|
||||||
r2 := Filter[string]([]string{"", "foo", "", "bar", ""}, func(x string, _ int) bool {
|
r2 := Filter([]string{"", "foo", "", "bar", ""}, func(x string, _ int) bool {
|
||||||
return len(x) > 0
|
return len(x) > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -36,10 +36,10 @@ func TestFilter(t *testing.T) {
|
|||||||
func TestMap(t *testing.T) {
|
func TestMap(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Map[int, string]([]int{1, 2, 3, 4}, func(x int, _ int) string {
|
result1 := Map([]int{1, 2, 3, 4}, func(x int, _ int) string {
|
||||||
return "Hello"
|
return "Hello"
|
||||||
})
|
})
|
||||||
result2 := Map[int64, string]([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
|
result2 := Map([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
|
||||||
return strconv.FormatInt(x, 10)
|
return strconv.FormatInt(x, 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -52,13 +52,13 @@ func TestMap(t *testing.T) {
|
|||||||
func TestFilterMap(t *testing.T) {
|
func TestFilterMap(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := FilterMap[int64, string]([]int64{1, 2, 3, 4}, func(x int64, _ int) (string, bool) {
|
r1 := FilterMap([]int64{1, 2, 3, 4}, func(x int64, _ int) (string, bool) {
|
||||||
if x%2 == 0 {
|
if x%2 == 0 {
|
||||||
return strconv.FormatInt(x, 10), true
|
return strconv.FormatInt(x, 10), true
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
})
|
})
|
||||||
r2 := FilterMap[string, string]([]string{"cpu", "gpu", "mouse", "keyboard"}, func(x string, _ int) (string, bool) {
|
r2 := FilterMap([]string{"cpu", "gpu", "mouse", "keyboard"}, func(x string, _ int) (string, bool) {
|
||||||
if strings.HasSuffix(x, "pu") {
|
if strings.HasSuffix(x, "pu") {
|
||||||
return "xpu", true
|
return "xpu", true
|
||||||
}
|
}
|
||||||
@@ -74,10 +74,10 @@ func TestFilterMap(t *testing.T) {
|
|||||||
func TestFlatMap(t *testing.T) {
|
func TestFlatMap(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := FlatMap[int, string]([]int{0, 1, 2, 3, 4}, func(x int, _ int) []string {
|
result1 := FlatMap([]int{0, 1, 2, 3, 4}, func(x int, _ int) []string {
|
||||||
return []string{"Hello"}
|
return []string{"Hello"}
|
||||||
})
|
})
|
||||||
result2 := FlatMap[int64, string]([]int64{0, 1, 2, 3, 4}, func(x int64, _ int) []string {
|
result2 := FlatMap([]int64{0, 1, 2, 3, 4}, func(x int64, _ int) []string {
|
||||||
result := make([]string, 0, x)
|
result := make([]string, 0, x)
|
||||||
for i := int64(0); i < x; i++ {
|
for i := int64(0); i < x; i++ {
|
||||||
result = append(result, strconv.FormatInt(x, 10))
|
result = append(result, strconv.FormatInt(x, 10))
|
||||||
@@ -94,7 +94,7 @@ func TestFlatMap(t *testing.T) {
|
|||||||
func TestTimes(t *testing.T) {
|
func TestTimes(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Times[string](3, func(i int) string {
|
result1 := Times(3, func(i int) string {
|
||||||
return strconv.FormatInt(int64(i), 10)
|
return strconv.FormatInt(int64(i), 10)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -105,10 +105,10 @@ func TestTimes(t *testing.T) {
|
|||||||
func TestReduce(t *testing.T) {
|
func TestReduce(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Reduce[int, int]([]int{1, 2, 3, 4}, func(agg int, item int, _ int) int {
|
result1 := Reduce([]int{1, 2, 3, 4}, func(agg int, item int, _ int) int {
|
||||||
return agg + item
|
return agg + item
|
||||||
}, 0)
|
}, 0)
|
||||||
result2 := Reduce[int, int]([]int{1, 2, 3, 4}, func(agg int, item int, _ int) int {
|
result2 := Reduce([]int{1, 2, 3, 4}, func(agg int, item int, _ int) int {
|
||||||
return agg + item
|
return agg + item
|
||||||
}, 10)
|
}, 10)
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ func TestForEach(t *testing.T) {
|
|||||||
callParams1 := []string{}
|
callParams1 := []string{}
|
||||||
callParams2 := []int{}
|
callParams2 := []int{}
|
||||||
|
|
||||||
ForEach[string]([]string{"a", "b", "c"}, func(item string, i int) {
|
ForEach([]string{"a", "b", "c"}, func(item string, i int) {
|
||||||
callParams1 = append(callParams1, item)
|
callParams1 = append(callParams1, item)
|
||||||
callParams2 = append(callParams2, i)
|
callParams2 = append(callParams2, i)
|
||||||
})
|
})
|
||||||
@@ -137,7 +137,7 @@ func TestForEach(t *testing.T) {
|
|||||||
func TestUniq(t *testing.T) {
|
func TestUniq(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Uniq[int]([]int{1, 2, 2, 1})
|
result1 := Uniq([]int{1, 2, 2, 1})
|
||||||
|
|
||||||
is.Equal(len(result1), 2)
|
is.Equal(len(result1), 2)
|
||||||
is.Equal(result1, []int{1, 2})
|
is.Equal(result1, []int{1, 2})
|
||||||
@@ -146,7 +146,7 @@ func TestUniq(t *testing.T) {
|
|||||||
func TestUniqBy(t *testing.T) {
|
func TestUniqBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := UniqBy[int, int]([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
|
result1 := UniqBy([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
|
||||||
return i % 3
|
return i % 3
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -157,25 +157,25 @@ func TestUniqBy(t *testing.T) {
|
|||||||
func TestGroupBy(t *testing.T) {
|
func TestGroupBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := GroupBy[int, int]([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
|
result1 := GroupBy([]int{0, 1, 2, 3, 4, 5}, func(i int) int {
|
||||||
return i % 3
|
return i % 3
|
||||||
})
|
})
|
||||||
|
|
||||||
is.Equal(len(result1), 3)
|
is.Equal(len(result1), 3)
|
||||||
is.Equal(result1, map[int][]int{
|
is.Equal(result1, map[int][]int{
|
||||||
0: []int{0, 3},
|
0: {0, 3},
|
||||||
1: []int{1, 4},
|
1: {1, 4},
|
||||||
2: []int{2, 5},
|
2: {2, 5},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChunk(t *testing.T) {
|
func TestChunk(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Chunk[int]([]int{0, 1, 2, 3, 4, 5}, 2)
|
result1 := Chunk([]int{0, 1, 2, 3, 4, 5}, 2)
|
||||||
result2 := Chunk[int]([]int{0, 1, 2, 3, 4, 5, 6}, 2)
|
result2 := Chunk([]int{0, 1, 2, 3, 4, 5, 6}, 2)
|
||||||
result3 := Chunk[int]([]int{}, 2)
|
result3 := Chunk([]int{}, 2)
|
||||||
result4 := Chunk[int]([]int{0}, 2)
|
result4 := Chunk([]int{0}, 2)
|
||||||
|
|
||||||
is.Equal(result1, [][]int{{0, 1}, {2, 3}, {4, 5}})
|
is.Equal(result1, [][]int{{0, 1}, {2, 3}, {4, 5}})
|
||||||
is.Equal(result2, [][]int{{0, 1}, {2, 3}, {4, 5}, {6}})
|
is.Equal(result2, [][]int{{0, 1}, {2, 3}, {4, 5}, {6}})
|
||||||
@@ -195,8 +195,8 @@ func TestPartitionBy(t *testing.T) {
|
|||||||
return "odd"
|
return "odd"
|
||||||
}
|
}
|
||||||
|
|
||||||
result1 := PartitionBy[int, string]([]int{-2, -1, 0, 1, 2, 3, 4, 5}, oddEven)
|
result1 := PartitionBy([]int{-2, -1, 0, 1, 2, 3, 4, 5}, oddEven)
|
||||||
result2 := PartitionBy[int, string]([]int{}, oddEven)
|
result2 := PartitionBy([]int{}, oddEven)
|
||||||
|
|
||||||
is.Equal(result1, [][]int{{-2, -1}, {0, 2, 4}, {1, 3, 5}})
|
is.Equal(result1, [][]int{{-2, -1}, {0, 2, 4}, {1, 3, 5}})
|
||||||
is.Equal(result2, [][]int{})
|
is.Equal(result2, [][]int{})
|
||||||
@@ -205,7 +205,7 @@ func TestPartitionBy(t *testing.T) {
|
|||||||
func TestFlatten(t *testing.T) {
|
func TestFlatten(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Flatten[int]([][]int{{0, 1}, {2, 3, 4, 5}})
|
result1 := Flatten([][]int{{0, 1}, {2, 3, 4, 5}})
|
||||||
|
|
||||||
is.Equal(result1, []int{0, 1, 2, 3, 4, 5})
|
is.Equal(result1, []int{0, 1, 2, 3, 4, 5})
|
||||||
}
|
}
|
||||||
@@ -213,8 +213,8 @@ func TestFlatten(t *testing.T) {
|
|||||||
func TestShuffle(t *testing.T) {
|
func TestShuffle(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Shuffle[int]([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
result1 := Shuffle([]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||||
result2 := Shuffle[int]([]int{})
|
result2 := Shuffle([]int{})
|
||||||
|
|
||||||
is.NotEqual(result1, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
is.NotEqual(result1, []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||||
is.Equal(result2, []int{})
|
is.Equal(result2, []int{})
|
||||||
@@ -223,9 +223,9 @@ func TestShuffle(t *testing.T) {
|
|||||||
func TestReverse(t *testing.T) {
|
func TestReverse(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Reverse[int]([]int{0, 1, 2, 3, 4, 5})
|
result1 := Reverse([]int{0, 1, 2, 3, 4, 5})
|
||||||
result2 := Reverse[int]([]int{0, 1, 2, 3, 4, 5, 6})
|
result2 := Reverse([]int{0, 1, 2, 3, 4, 5, 6})
|
||||||
result3 := Reverse[int]([]int{})
|
result3 := Reverse([]int{})
|
||||||
|
|
||||||
is.Equal(result1, []int{5, 4, 3, 2, 1, 0})
|
is.Equal(result1, []int{5, 4, 3, 2, 1, 0})
|
||||||
is.Equal(result2, []int{6, 5, 4, 3, 2, 1, 0})
|
is.Equal(result2, []int{6, 5, 4, 3, 2, 1, 0})
|
||||||
@@ -235,20 +235,20 @@ func TestReverse(t *testing.T) {
|
|||||||
func TestFill(t *testing.T) {
|
func TestFill(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Fill[foo]([]foo{foo{"a"}, foo{"a"}}, foo{"b"})
|
result1 := Fill([]foo{{"a"}, {"a"}}, foo{"b"})
|
||||||
result2 := Fill[foo]([]foo{}, foo{"a"})
|
result2 := Fill([]foo{}, foo{"a"})
|
||||||
|
|
||||||
is.Equal(result1, []foo{foo{"b"}, foo{"b"}})
|
is.Equal(result1, []foo{{"b"}, {"b"}})
|
||||||
is.Equal(result2, []foo{})
|
is.Equal(result2, []foo{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepeat(t *testing.T) {
|
func TestRepeat(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := Repeat[foo](2, foo{"a"})
|
result1 := Repeat(2, foo{"a"})
|
||||||
result2 := Repeat[foo](0, foo{"a"})
|
result2 := Repeat(0, foo{"a"})
|
||||||
|
|
||||||
is.Equal(result1, []foo{foo{"a"}, foo{"a"}})
|
is.Equal(result1, []foo{{"a"}, {"a"}})
|
||||||
is.Equal(result2, []foo{})
|
is.Equal(result2, []foo{})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,9 +259,9 @@ func TestRepeatBy(t *testing.T) {
|
|||||||
return int(math.Pow(float64(i), 2))
|
return int(math.Pow(float64(i), 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
result1 := RepeatBy[int](0, cb)
|
result1 := RepeatBy(0, cb)
|
||||||
result2 := RepeatBy[int](2, cb)
|
result2 := RepeatBy(2, cb)
|
||||||
result3 := RepeatBy[int](5, cb)
|
result3 := RepeatBy(5, cb)
|
||||||
|
|
||||||
is.Equal([]int{}, result1)
|
is.Equal([]int{}, result1)
|
||||||
is.Equal([]int{0, 1}, result2)
|
is.Equal([]int{0, 1}, result2)
|
||||||
@@ -271,7 +271,7 @@ func TestRepeatBy(t *testing.T) {
|
|||||||
func TestKeyBy(t *testing.T) {
|
func TestKeyBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := KeyBy[int, string]([]string{"a", "aa", "aaa"}, func(str string) int {
|
result1 := KeyBy([]string{"a", "aa", "aaa"}, func(str string) int {
|
||||||
return len(str)
|
return len(str)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -339,13 +339,13 @@ func TestDropRightWhile(t *testing.T) {
|
|||||||
func TestReject(t *testing.T) {
|
func TestReject(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := Reject[int]([]int{1, 2, 3, 4}, func(x int, _ int) bool {
|
r1 := Reject([]int{1, 2, 3, 4}, func(x int, _ int) bool {
|
||||||
return x%2 == 0
|
return x%2 == 0
|
||||||
})
|
})
|
||||||
|
|
||||||
is.Equal(r1, []int{1, 3})
|
is.Equal(r1, []int{1, 3})
|
||||||
|
|
||||||
r2 := Reject[string]([]string{"Smith", "foo", "Domin", "bar", "Olivia"}, func(x string, _ int) bool {
|
r2 := Reject([]string{"Smith", "foo", "Domin", "bar", "Olivia"}, func(x string, _ int) bool {
|
||||||
return len(x) > 3
|
return len(x) > 3
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -355,9 +355,9 @@ func TestReject(t *testing.T) {
|
|||||||
func TestCount(t *testing.T) {
|
func TestCount(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
count1 := Count[int]([]int{1, 2, 1}, 1)
|
count1 := Count([]int{1, 2, 1}, 1)
|
||||||
count2 := Count[int]([]int{1, 2, 1}, 3)
|
count2 := Count([]int{1, 2, 1}, 3)
|
||||||
count3 := Count[int]([]int{}, 1)
|
count3 := Count([]int{}, 1)
|
||||||
|
|
||||||
is.Equal(count1, 2)
|
is.Equal(count1, 2)
|
||||||
is.Equal(count2, 0)
|
is.Equal(count2, 0)
|
||||||
@@ -367,15 +367,15 @@ func TestCount(t *testing.T) {
|
|||||||
func TestCountBy(t *testing.T) {
|
func TestCountBy(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
count1 := CountBy[int]([]int{1, 2, 1}, func(i int) bool {
|
count1 := CountBy([]int{1, 2, 1}, func(i int) bool {
|
||||||
return i < 2
|
return i < 2
|
||||||
})
|
})
|
||||||
|
|
||||||
count2 := CountBy[int]([]int{1, 2, 1}, func(i int) bool {
|
count2 := CountBy([]int{1, 2, 1}, func(i int) bool {
|
||||||
return i > 2
|
return i > 2
|
||||||
})
|
})
|
||||||
|
|
||||||
count3 := CountBy[int]([]int{}, func(i int) bool {
|
count3 := CountBy([]int{}, func(i int) bool {
|
||||||
return i <= 2
|
return i <= 2
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
104
tuples.go
104
tuples.go
@@ -84,13 +84,13 @@ func Unpack9[A any, B any, C any, D any, E any, F any, G any, H any, I any](tupl
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] {
|
func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] {
|
||||||
size := Max[int]([]int{len(a), len(b)})
|
size := Max([]int{len(a), len(b)})
|
||||||
|
|
||||||
result := make([]Tuple2[A, B], 0, size)
|
result := make([]Tuple2[A, B], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
|
|
||||||
result = append(result, Tuple2[A, B]{
|
result = append(result, Tuple2[A, B]{
|
||||||
A: _a,
|
A: _a,
|
||||||
@@ -105,14 +105,14 @@ func Zip2[A any, B any](a []A, b []B) []Tuple2[A, B] {
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C] {
|
func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C] {
|
||||||
size := Max[int]([]int{len(a), len(b), len(c)})
|
size := Max([]int{len(a), len(b), len(c)})
|
||||||
|
|
||||||
result := make([]Tuple3[A, B, C], 0, size)
|
result := make([]Tuple3[A, B, C], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
_c, _ := Nth[C](c, index)
|
_c, _ := Nth(c, index)
|
||||||
|
|
||||||
result = append(result, Tuple3[A, B, C]{
|
result = append(result, Tuple3[A, B, C]{
|
||||||
A: _a,
|
A: _a,
|
||||||
@@ -128,15 +128,15 @@ func Zip3[A any, B any, C any](a []A, b []B, c []C) []Tuple3[A, B, C] {
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D] {
|
func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B, C, D] {
|
||||||
size := Max[int]([]int{len(a), len(b), len(c), len(d)})
|
size := Max([]int{len(a), len(b), len(c), len(d)})
|
||||||
|
|
||||||
result := make([]Tuple4[A, B, C, D], 0, size)
|
result := make([]Tuple4[A, B, C, D], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
_c, _ := Nth[C](c, index)
|
_c, _ := Nth(c, index)
|
||||||
_d, _ := Nth[D](d, index)
|
_d, _ := Nth(d, index)
|
||||||
|
|
||||||
result = append(result, Tuple4[A, B, C, D]{
|
result = append(result, Tuple4[A, B, C, D]{
|
||||||
A: _a,
|
A: _a,
|
||||||
@@ -153,16 +153,16 @@ func Zip4[A any, B any, C any, D any](a []A, b []B, c []C, d []D) []Tuple4[A, B,
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E] {
|
func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E) []Tuple5[A, B, C, D, E] {
|
||||||
size := Max[int]([]int{len(a), len(b), len(c), len(d), len(e)})
|
size := Max([]int{len(a), len(b), len(c), len(d), len(e)})
|
||||||
|
|
||||||
result := make([]Tuple5[A, B, C, D, E], 0, size)
|
result := make([]Tuple5[A, B, C, D, E], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
_c, _ := Nth[C](c, index)
|
_c, _ := Nth(c, index)
|
||||||
_d, _ := Nth[D](d, index)
|
_d, _ := Nth(d, index)
|
||||||
_e, _ := Nth[E](e, index)
|
_e, _ := Nth(e, index)
|
||||||
|
|
||||||
result = append(result, Tuple5[A, B, C, D, E]{
|
result = append(result, Tuple5[A, B, C, D, E]{
|
||||||
A: _a,
|
A: _a,
|
||||||
@@ -180,17 +180,17 @@ func Zip5[A any, B any, C any, D any, E any](a []A, b []B, c []C, d []D, e []E)
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F] {
|
func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D, e []E, f []F) []Tuple6[A, B, C, D, E, F] {
|
||||||
size := Max[int]([]int{len(a), len(b), len(c), len(d), len(e), len(f)})
|
size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f)})
|
||||||
|
|
||||||
result := make([]Tuple6[A, B, C, D, E, F], 0, size)
|
result := make([]Tuple6[A, B, C, D, E, F], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
_c, _ := Nth[C](c, index)
|
_c, _ := Nth(c, index)
|
||||||
_d, _ := Nth[D](d, index)
|
_d, _ := Nth(d, index)
|
||||||
_e, _ := Nth[E](e, index)
|
_e, _ := Nth(e, index)
|
||||||
_f, _ := Nth[F](f, index)
|
_f, _ := Nth(f, index)
|
||||||
|
|
||||||
result = append(result, Tuple6[A, B, C, D, E, F]{
|
result = append(result, Tuple6[A, B, C, D, E, F]{
|
||||||
A: _a,
|
A: _a,
|
||||||
@@ -209,18 +209,18 @@ func Zip6[A any, B any, C any, D any, E any, F any](a []A, b []B, c []C, d []D,
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G] {
|
func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C, d []D, e []E, f []F, g []G) []Tuple7[A, B, C, D, E, F, G] {
|
||||||
size := Max[int]([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g)})
|
size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g)})
|
||||||
|
|
||||||
result := make([]Tuple7[A, B, C, D, E, F, G], 0, size)
|
result := make([]Tuple7[A, B, C, D, E, F, G], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
_c, _ := Nth[C](c, index)
|
_c, _ := Nth(c, index)
|
||||||
_d, _ := Nth[D](d, index)
|
_d, _ := Nth(d, index)
|
||||||
_e, _ := Nth[E](e, index)
|
_e, _ := Nth(e, index)
|
||||||
_f, _ := Nth[F](f, index)
|
_f, _ := Nth(f, index)
|
||||||
_g, _ := Nth[G](g, index)
|
_g, _ := Nth(g, index)
|
||||||
|
|
||||||
result = append(result, Tuple7[A, B, C, D, E, F, G]{
|
result = append(result, Tuple7[A, B, C, D, E, F, G]{
|
||||||
A: _a,
|
A: _a,
|
||||||
@@ -240,19 +240,19 @@ func Zip7[A any, B any, C any, D any, E any, F any, G any](a []A, b []B, c []C,
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H] {
|
func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H) []Tuple8[A, B, C, D, E, F, G, H] {
|
||||||
size := Max[int]([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h)})
|
size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h)})
|
||||||
|
|
||||||
result := make([]Tuple8[A, B, C, D, E, F, G, H], 0, size)
|
result := make([]Tuple8[A, B, C, D, E, F, G, H], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
_c, _ := Nth[C](c, index)
|
_c, _ := Nth(c, index)
|
||||||
_d, _ := Nth[D](d, index)
|
_d, _ := Nth(d, index)
|
||||||
_e, _ := Nth[E](e, index)
|
_e, _ := Nth(e, index)
|
||||||
_f, _ := Nth[F](f, index)
|
_f, _ := Nth(f, index)
|
||||||
_g, _ := Nth[G](g, index)
|
_g, _ := Nth(g, index)
|
||||||
_h, _ := Nth[H](h, index)
|
_h, _ := Nth(h, index)
|
||||||
|
|
||||||
result = append(result, Tuple8[A, B, C, D, E, F, G, H]{
|
result = append(result, Tuple8[A, B, C, D, E, F, G, H]{
|
||||||
A: _a,
|
A: _a,
|
||||||
@@ -273,20 +273,20 @@ func Zip8[A any, B any, C any, D any, E any, F any, G any, H any](a []A, b []B,
|
|||||||
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
// of the given arrays, the second of which contains the second elements of the given arrays, and so on.
|
||||||
// When collections have different size, the Tuple attributes are filled with zero value.
|
// When collections have different size, the Tuple attributes are filled with zero value.
|
||||||
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I] {
|
func Zip9[A any, B any, C any, D any, E any, F any, G any, H any, I any](a []A, b []B, c []C, d []D, e []E, f []F, g []G, h []H, i []I) []Tuple9[A, B, C, D, E, F, G, H, I] {
|
||||||
size := Max[int]([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i)})
|
size := Max([]int{len(a), len(b), len(c), len(d), len(e), len(f), len(g), len(h), len(i)})
|
||||||
|
|
||||||
result := make([]Tuple9[A, B, C, D, E, F, G, H, I], 0, size)
|
result := make([]Tuple9[A, B, C, D, E, F, G, H, I], 0, size)
|
||||||
|
|
||||||
for index := 0; index < size; index++ {
|
for index := 0; index < size; index++ {
|
||||||
_a, _ := Nth[A](a, index)
|
_a, _ := Nth(a, index)
|
||||||
_b, _ := Nth[B](b, index)
|
_b, _ := Nth(b, index)
|
||||||
_c, _ := Nth[C](c, index)
|
_c, _ := Nth(c, index)
|
||||||
_d, _ := Nth[D](d, index)
|
_d, _ := Nth(d, index)
|
||||||
_e, _ := Nth[E](e, index)
|
_e, _ := Nth(e, index)
|
||||||
_f, _ := Nth[F](f, index)
|
_f, _ := Nth(f, index)
|
||||||
_g, _ := Nth[G](g, index)
|
_g, _ := Nth(g, index)
|
||||||
_h, _ := Nth[H](h, index)
|
_h, _ := Nth(h, index)
|
||||||
_i, _ := Nth[I](i, index)
|
_i, _ := Nth(i, index)
|
||||||
|
|
||||||
result = append(result, Tuple9[A, B, C, D, E, F, G, H, I]{
|
result = append(result, Tuple9[A, B, C, D, E, F, G, H, I]{
|
||||||
A: _a,
|
A: _a,
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import (
|
|||||||
func TestT(t *testing.T) {
|
func TestT(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := T2[string, int]("a", 1)
|
r1 := T2("a", 1)
|
||||||
r2 := T3[string, int, float32]("b", 2, 3.0)
|
r2 := T3[string, int, float32]("b", 2, 3.0)
|
||||||
r3 := T4[string, int, float32, bool]("c", 3, 4.0, true)
|
r3 := T4[string, int, float32]("c", 3, 4.0, true)
|
||||||
r4 := T5[string, int, float32, bool, string]("d", 4, 5.0, false, "e")
|
r4 := T5[string, int, float32]("d", 4, 5.0, false, "e")
|
||||||
r5 := T6[string, int, float32, bool, string, int]("f", 5, 6.0, true, "g", 7)
|
r5 := T6[string, int, float32]("f", 5, 6.0, true, "g", 7)
|
||||||
r6 := T7[string, int, float32, bool, string, int, float64]("h", 6, 7.0, false, "i", 8, 9.0)
|
r6 := T7[string, int, float32]("h", 6, 7.0, false, "i", 8, 9.0)
|
||||||
r7 := T8[string, int, float32, bool, string, int, float64, bool]("j", 7, 8.0, true, "k", 9, 10.0, false)
|
r7 := T8[string, int, float32]("j", 7, 8.0, true, "k", 9, 10.0, false)
|
||||||
r8 := T9[string, int, float32, bool, string, int, float64, bool, string]("l", 8, 9.0, false, "m", 10, 11.0, true, "n")
|
r8 := T9[string, int, float32]("l", 8, 9.0, false, "m", 10, 11.0, true, "n")
|
||||||
|
|
||||||
is.Equal(r1, Tuple2[string, int]{A: "a", B: 1})
|
is.Equal(r1, Tuple2[string, int]{A: "a", B: 1})
|
||||||
is.Equal(r2, Tuple3[string, int, float32]{A: "b", B: 2, C: 3.0})
|
is.Equal(r2, Tuple3[string, int, float32]{A: "b", B: 2, C: 3.0})
|
||||||
@@ -34,7 +34,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple2[string, int]{"a", 1}
|
tuple := Tuple2[string, int]{"a", 1}
|
||||||
|
|
||||||
r1, r2 := Unpack2[string, int](tuple)
|
r1, r2 := Unpack2(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -43,7 +43,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple3[string, int, float64]{"a", 1, 1.0}
|
tuple := Tuple3[string, int, float64]{"a", 1, 1.0}
|
||||||
|
|
||||||
r1, r2, r3 := Unpack3[string, int, float64](tuple)
|
r1, r2, r3 := Unpack3(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -53,7 +53,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple4[string, int, float64, bool]{"a", 1, 1.0, true}
|
tuple := Tuple4[string, int, float64, bool]{"a", 1, 1.0, true}
|
||||||
|
|
||||||
r1, r2, r3, r4 := Unpack4[string, int, float64, bool](tuple)
|
r1, r2, r3, r4 := Unpack4(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -64,7 +64,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple5[string, int, float64, bool, string]{"a", 1, 1.0, true, "b"}
|
tuple := Tuple5[string, int, float64, bool, string]{"a", 1, 1.0, true, "b"}
|
||||||
|
|
||||||
r1, r2, r3, r4, r5 := Unpack5[string, int, float64, bool, string](tuple)
|
r1, r2, r3, r4, r5 := Unpack5(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -76,7 +76,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple6[string, int, float64, bool, string, int]{"a", 1, 1.0, true, "b", 2}
|
tuple := Tuple6[string, int, float64, bool, string, int]{"a", 1, 1.0, true, "b", 2}
|
||||||
|
|
||||||
r1, r2, r3, r4, r5, r6 := Unpack6[string, int, float64, bool, string, int](tuple)
|
r1, r2, r3, r4, r5, r6 := Unpack6(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -89,7 +89,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple7[string, int, float64, bool, string, int, float64]{"a", 1, 1.0, true, "b", 2, 3.0}
|
tuple := Tuple7[string, int, float64, bool, string, int, float64]{"a", 1, 1.0, true, "b", 2, 3.0}
|
||||||
|
|
||||||
r1, r2, r3, r4, r5, r6, r7 := Unpack7[string, int, float64, bool, string, int, float64](tuple)
|
r1, r2, r3, r4, r5, r6, r7 := Unpack7(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -103,7 +103,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple8[string, int, float64, bool, string, int, float64, bool]{"a", 1, 1.0, true, "b", 2, 3.0, true}
|
tuple := Tuple8[string, int, float64, bool, string, int, float64, bool]{"a", 1, 1.0, true, "b", 2, 3.0, true}
|
||||||
|
|
||||||
r1, r2, r3, r4, r5, r6, r7, r8 := Unpack8[string, int, float64, bool, string, int, float64, bool](tuple)
|
r1, r2, r3, r4, r5, r6, r7, r8 := Unpack8(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -118,7 +118,7 @@ func TestUnpack(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tuple := Tuple9[string, int, float64, bool, string, int, float64, bool, string]{"a", 1, 1.0, true, "b", 2, 3.0, true, "c"}
|
tuple := Tuple9[string, int, float64, bool, string, int, float64, bool, string]{"a", 1, 1.0, true, "b", 2, 3.0, true, "c"}
|
||||||
|
|
||||||
r1, r2, r3, r4, r5, r6, r7, r8, r9 := Unpack9[string, int, float64, bool, string, int, float64, bool, string](tuple)
|
r1, r2, r3, r4, r5, r6, r7, r8, r9 := Unpack9(tuple)
|
||||||
|
|
||||||
is.Equal("a", r1)
|
is.Equal("a", r1)
|
||||||
is.Equal(1, r2)
|
is.Equal(1, r2)
|
||||||
@@ -135,24 +135,24 @@ func TestUnpack(t *testing.T) {
|
|||||||
func TestZip(t *testing.T) {
|
func TestZip(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1 := Zip2[string, int](
|
r1 := Zip2(
|
||||||
[]string{"a", "b"},
|
[]string{"a", "b"},
|
||||||
[]int{1, 2},
|
[]int{1, 2},
|
||||||
)
|
)
|
||||||
|
|
||||||
r2 := Zip3[string, int, int](
|
r2 := Zip3(
|
||||||
[]string{"a", "b", "c"},
|
[]string{"a", "b", "c"},
|
||||||
[]int{1, 2, 3}, []int{4, 5, 6},
|
[]int{1, 2, 3}, []int{4, 5, 6},
|
||||||
)
|
)
|
||||||
|
|
||||||
r3 := Zip4[string, int, int, bool](
|
r3 := Zip4(
|
||||||
[]string{"a", "b", "c", "d"},
|
[]string{"a", "b", "c", "d"},
|
||||||
[]int{1, 2, 3, 4},
|
[]int{1, 2, 3, 4},
|
||||||
[]int{5, 6, 7, 8},
|
[]int{5, 6, 7, 8},
|
||||||
[]bool{true, true, true, true},
|
[]bool{true, true, true, true},
|
||||||
)
|
)
|
||||||
|
|
||||||
r4 := Zip5[string, int, int, bool, float32](
|
r4 := Zip5(
|
||||||
[]string{"a", "b", "c", "d", "e"},
|
[]string{"a", "b", "c", "d", "e"},
|
||||||
[]int{1, 2, 3, 4, 5},
|
[]int{1, 2, 3, 4, 5},
|
||||||
[]int{6, 7, 8, 9, 10},
|
[]int{6, 7, 8, 9, 10},
|
||||||
@@ -160,7 +160,7 @@ func TestZip(t *testing.T) {
|
|||||||
[]float32{0.1, 0.2, 0.3, 0.4, 0.5},
|
[]float32{0.1, 0.2, 0.3, 0.4, 0.5},
|
||||||
)
|
)
|
||||||
|
|
||||||
r5 := Zip6[string, int, int, bool, float32, float64](
|
r5 := Zip6(
|
||||||
[]string{"a", "b", "c", "d", "e", "f"},
|
[]string{"a", "b", "c", "d", "e", "f"},
|
||||||
[]int{1, 2, 3, 4, 5, 6},
|
[]int{1, 2, 3, 4, 5, 6},
|
||||||
[]int{7, 8, 9, 10, 11, 12},
|
[]int{7, 8, 9, 10, 11, 12},
|
||||||
@@ -169,7 +169,7 @@ func TestZip(t *testing.T) {
|
|||||||
[]float64{0.01, 0.02, 0.03, 0.04, 0.05, 0.06},
|
[]float64{0.01, 0.02, 0.03, 0.04, 0.05, 0.06},
|
||||||
)
|
)
|
||||||
|
|
||||||
r6 := Zip7[string, int, int, bool, float32, float64, int8](
|
r6 := Zip7(
|
||||||
[]string{"a", "b", "c", "d", "e", "f", "g"},
|
[]string{"a", "b", "c", "d", "e", "f", "g"},
|
||||||
[]int{1, 2, 3, 4, 5, 6, 7},
|
[]int{1, 2, 3, 4, 5, 6, 7},
|
||||||
[]int{8, 9, 10, 11, 12, 13, 14},
|
[]int{8, 9, 10, 11, 12, 13, 14},
|
||||||
@@ -179,7 +179,7 @@ func TestZip(t *testing.T) {
|
|||||||
[]int8{1, 2, 3, 4, 5, 6, 7},
|
[]int8{1, 2, 3, 4, 5, 6, 7},
|
||||||
)
|
)
|
||||||
|
|
||||||
r7 := Zip8[string, int, int, bool, float32, float64, int8, int16](
|
r7 := Zip8(
|
||||||
[]string{"a", "b", "c", "d", "e", "f", "g", "h"},
|
[]string{"a", "b", "c", "d", "e", "f", "g", "h"},
|
||||||
[]int{1, 2, 3, 4, 5, 6, 7, 8},
|
[]int{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
[]int{9, 10, 11, 12, 13, 14, 15, 16},
|
[]int{9, 10, 11, 12, 13, 14, 15, 16},
|
||||||
@@ -190,7 +190,7 @@ func TestZip(t *testing.T) {
|
|||||||
[]int16{1, 2, 3, 4, 5, 6, 7, 8},
|
[]int16{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
)
|
)
|
||||||
|
|
||||||
r8 := Zip9[string, int, int, bool, float32, float64, int8, int16, int32](
|
r8 := Zip9(
|
||||||
[]string{"a", "b", "c", "d", "e", "f", "g", "h", "i"},
|
[]string{"a", "b", "c", "d", "e", "f", "g", "h", "i"},
|
||||||
[]int{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
[]int{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||||
[]int{10, 11, 12, 13, 14, 15, 16, 17, 18},
|
[]int{10, 11, 12, 13, 14, 15, 16, 17, 18},
|
||||||
@@ -274,7 +274,7 @@ func TestZip(t *testing.T) {
|
|||||||
func TestUnzip(t *testing.T) {
|
func TestUnzip(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
r1, r2 := Unzip2[string, int]([]Tuple2[string, int]{{A: "a", B: 1}, {A: "b", B: 2}})
|
r1, r2 := Unzip2([]Tuple2[string, int]{{A: "a", B: 1}, {A: "b", B: 2}})
|
||||||
|
|
||||||
is.Equal(r1, []string{"a", "b"})
|
is.Equal(r1, []string{"a", "b"})
|
||||||
is.Equal(r2, []int{1, 2})
|
is.Equal(r2, []int{1, 2})
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
func TestToPtr(t *testing.T) {
|
func TestToPtr(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
|
|
||||||
result1 := ToPtr[[]int]([]int{1, 2})
|
result1 := ToPtr([]int{1, 2})
|
||||||
|
|
||||||
is.Equal(*result1, []int{1, 2})
|
is.Equal(*result1, []int{1, 2})
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ func TestToSlicePtr(t *testing.T) {
|
|||||||
|
|
||||||
str1 := "foo"
|
str1 := "foo"
|
||||||
str2 := "bar"
|
str2 := "bar"
|
||||||
result1 := ToSlicePtr[string]([]string{str1, str2})
|
result1 := ToSlicePtr([]string{str1, str2})
|
||||||
|
|
||||||
is.Equal(result1, []*string{&str1, &str2})
|
is.Equal(result1, []*string{&str1, &str2})
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ func TestCoalesce(t *testing.T) {
|
|||||||
|
|
||||||
result1, ok1 := Coalesce[int]()
|
result1, ok1 := Coalesce[int]()
|
||||||
result2, ok2 := Coalesce(3)
|
result2, ok2 := Coalesce(3)
|
||||||
result3, ok3 := Coalesce[*string](nil, nilStr)
|
result3, ok3 := Coalesce(nil, nilStr)
|
||||||
result4, ok4 := Coalesce(nilStr, str1)
|
result4, ok4 := Coalesce(nilStr, str1)
|
||||||
result5, ok5 := Coalesce(nilStr, str1, str2)
|
result5, ok5 := Coalesce(nilStr, str1, str2)
|
||||||
result6, ok6 := Coalesce(str1, str2, nilStr)
|
result6, ok6 := Coalesce(str1, str2, nilStr)
|
||||||
|
|||||||
Reference in New Issue
Block a user