1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-10 07:42:27 +08:00

feat: add UniqueBy function in slice.go

This commit is contained in:
dudaodong
2022-06-22 12:00:01 +08:00
parent 24d4a03227
commit 2d7e19fb87
2 changed files with 34 additions and 0 deletions

View File

@@ -418,6 +418,15 @@ func TestUnique(t *testing.T) {
assert.Equal([]string{"a", "b", "c"}, Unique([]string{"a", "a", "b", "c"}))
}
func TestUniqueBy(t *testing.T) {
assert := internal.NewAssert(t, "TestUniqueBy")
actual := UniqueBy([]int{1, 2, 3, 4, 5, 6}, func(val int) int {
return val % 4
})
assert.Equal([]int{1, 2, 3, 0}, actual)
}
func TestUnion(t *testing.T) {
assert := internal.NewAssert(t, "TestUnion")