25 lines
433 B
Go
25 lines
433 B
Go
package sieve_test
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/sieve"
|
|
)
|
|
|
|
type post struct {
|
|
ID int
|
|
Title string
|
|
}
|
|
|
|
func ExampleMap() {
|
|
posts := []post{
|
|
{ID: 1, Title: "Hello"},
|
|
{ID: 2, Title: "Summer"},
|
|
{ID: 3, Title: "Goodbye"},
|
|
}
|
|
// Pluck the titles with a field accessor.
|
|
titles := sieve.Map(posts, func(p post) string { return p.Title })
|
|
fmt.Println(titles)
|
|
// Output: [Hello Summer Goodbye]
|
|
}
|