mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-09-27 03:15:55 +08:00
22 lines
280 B
Go
22 lines
280 B
Go
package slicex
|
|
|
|
import "fmt"
|
|
|
|
func ExamplePluck() {
|
|
type Person struct {
|
|
ID int
|
|
Name string
|
|
}
|
|
persons := []Person{
|
|
{1, "Alice"},
|
|
{2, "Bob"},
|
|
{3, "Charlie"},
|
|
}
|
|
|
|
keys := Pluck(persons, func(p Person) int {
|
|
return p.ID
|
|
})
|
|
fmt.Println(keys)
|
|
// Output: [1 2 3]
|
|
}
|