mirror of
				https://github.com/samber/lo.git
				synced 2025-10-31 19:43:08 +08:00 
			
		
		
		
	 5196e100c3
			
		
	
	5196e100c3
	
	
	
		
			
			* 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}]
 | |
| }
 |