feat(sieve): add sieve module with Map
This commit is contained in:
24
modules/sieve/example_test.go
Normal file
24
modules/sieve/example_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
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]
|
||||
}
|
||||
Reference in New Issue
Block a user