1
0
gomponents/gomponents_generic.go
Markus Wüstenberg f387a71230
Add generic Map implementation (#108)
Instead of waiting for a good time to switch the `Map` implementation,
I've decided to just offer two implementations: one for Go versions
before 1.18, and one for 1.18 and onwards. This is achieved using build
tags in the source files.

This is obviously a breaking change for consumers of this library that
use Go 1.18 and onwards.

See #88
2022-09-22 09:41:06 +02:00

14 lines
246 B
Go

//go:build go1.18
// +build go1.18
package gomponents
// 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
}