mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(slice): handle Intersection without inputs (#366)
This commit is contained in:
1 parent
129da3f2ed
commit
f220ea4c3f
2 files changed
+4
No files matched your search
@@ -1019,6 +1019,9 @@ func Merge[T any](slices ...[]T) []T {
|
|||||||
// Play: https://go.dev/play/p/anJXfB5wq_t
|
// Play: https://go.dev/play/p/anJXfB5wq_t
|
||||||
func Intersection[T comparable](slices ...[]T) []T {
|
func Intersection[T comparable](slices ...[]T) []T {
|
||||||
result := []T{}
|
result := []T{}
|
||||||
|
if len(slices) == 0 {
|
||||||
|
return result
|
||||||
|
}
|
||||||
elementCount := make(map[T]int)
|
elementCount := make(map[T]int)
|
||||||
|
|
||||||
for _, slice := range slices {
|
for _, slice := range slices {
|
||||||
|
|||||||
@@ -1105,6 +1105,7 @@ func TestIntersection(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
assert := internal.NewAssert(t, "TestIntersection")
|
assert := internal.NewAssert(t, "TestIntersection")
|
||||||
|
assert.Equal([]int{}, Intersection[int]())
|
||||||
|
|
||||||
s1 := []int{1, 2, 2, 3}
|
s1 := []int{1, 2, 2, 3}
|
||||||
s2 := []int{1, 2, 3, 4}
|
s2 := []int{1, 2, 3, 4}
|
||||||
|
|||||||
Reference in new issue
Block a user