feat(sieve): add sieve module with Map

This commit is contained in:
2026-10-11 14:22:56 +02:00
parent b906bdd48b
commit 6933004b87
4 changed files with 103 additions and 0 deletions

View 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]
}