feat: add KeyBy for slice

This commit is contained in:
dudaodong committed 2022-11-05 16:52:31 +08:00
1 parent 8c036f830c
commit 260fb795d3
2 files changed
+22

No files matched your search

+10
View File
@@ -644,3 +644,13 @@ func TestReplaceAll(t *testing.T) {
assert.Equal([]string{"x", "b", "x", "c", "d", "x"}, ReplaceAll(strs, "a", "x"))
assert.Equal([]string{"a", "b", "a", "c", "d", "a"}, ReplaceAll(strs, "e", "x"))
}
func TestKeyBy(t *testing.T) {
assert := internal.NewAssert(t, "TestKeyBy")
result := KeyBy([]string{"a", "ab", "abc"}, func(str string) int {
return len(str)
})
assert.Equal(result, map[int]string{1: "a", 2: "ab", 3: "abc"})
}