mirror of
https://github.com/samber/lo.git
synced 2025-10-31 03:26:24 +08:00
feat: add WithoutBy example test
This commit is contained in:
34
intersect_example_test.go
Normal file
34
intersect_example_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package lo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func ExampleWithoutBy() {
|
||||
type user struct {
|
||||
id int
|
||||
name string
|
||||
}
|
||||
// Example usage
|
||||
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\n", filteredUsers)
|
||||
// Output:
|
||||
// [{1 Alice}]
|
||||
}
|
||||
Reference in New Issue
Block a user