about summary refs log tree commit diff stats
path: root/gomponents.go
diff options
context:
space:
mode:
Diffstat (limited to 'gomponents.go')
-rw-r--r--gomponents.go9
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
 }