1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 22:52:29 +08:00

feat: add UniqueByField

This commit is contained in:
dudaodong
2024-06-24 19:36:02 +08:00
parent ca373b00a7
commit 95b516e278
3 changed files with 91 additions and 1 deletions

View File

@@ -780,6 +780,28 @@ func ExampleUniqueBy() {
// [1 2 0]
}
func ExampleUniqueByField() {
type User struct {
ID int `json:"id"`
Name string `json:"name"`
}
users := []User{
{ID: 1, Name: "a"},
{ID: 2, Name: "b"},
{ID: 1, Name: "c"},
}
result, err := UniqueByField(users, "ID")
if err != nil {
}
fmt.Println(result)
// Output:
// [{1 a} {2 b}]
}
func ExampleUnion() {
nums1 := []int{1, 3, 4, 6}
nums2 := []int{1, 2, 5, 6}