mirror of
https://github.com/samber/lo.git
synced 2025-09-26 20:11:13 +08:00

* lint: pin golangci-lint version * fix: minor example issues * Update lint.yml --------- Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
35 lines
561 B
Go
35 lines
561 B
Go
package lo
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func ExampleWithoutBy() {
|
|
type User struct {
|
|
ID int
|
|
Name string
|
|
}
|
|
// original users
|
|
users := []User{
|
|
{ID: 1, Name: "Alice"},
|
|
{ID: 2, Name: "Bob"},
|
|
{ID: 3, Name: "Charlie"},
|
|
}
|
|
|
|
// exclude users with IDs 2 and 3
|
|
excludedIDs := []int{2, 3}
|
|
|
|
// extract function to get the user ID
|
|
extractID := func(user User) int {
|
|
return user.ID
|
|
}
|
|
|
|
// filtering users
|
|
filteredUsers := WithoutBy(users, extractID, excludedIDs...)
|
|
|
|
// output the filtered users
|
|
fmt.Printf("%v", filteredUsers)
|
|
// Output:
|
|
// [{1 Alice}]
|
|
}
|