Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add WithoutBy #515

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: add WithoutBy example test
  • Loading branch information
nicklaus-dev committed Aug 17, 2024
commit 21f10dac8f3984f94bbcf26c0095eb79adf03e3e
34 changes: 34 additions & 0 deletions intersect_example_test.go
Original file line number Diff line number Diff line change
@@ -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}]
}