diff options
Diffstat (limited to 'gomponents.go')
-rw-r--r-- | gomponents.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gomponents.go b/gomponents.go index ffe8483..1a3b4ee 100644 --- a/gomponents.go +++ b/gomponents.go @@ -246,6 +246,15 @@ func Rawf(format string, a ...interface{}) Node { }) } +// Map a slice of anything to a slice of Nodes. +func Map[T any](ts []T, cb func(T) Node) []Node { + var nodes []Node + for _, t := range ts { + nodes = append(nodes, cb(t)) + } + return nodes +} + type group struct { children []Node } |