all repos — gomponents @ f387a7123040d9414350bf783bdeff17ac0572c7

HTML components in pure Go

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

Markus Wüstenberg
commit

f387a7123040d9414350bf783bdeff17ac0572c7

parent

3334d6c7d049cec57ad36f9d5cb0d491faf54a5d

1 file changed, 13 insertions(+), 0 deletions(-)

changed files
A gomponents_non_generic.go
@@ -0,0 +1,13 @@
+//go:build !go1.18 +// +build !go1.18 + +package gomponents + +// Map something enumerable to a list of Nodes. +func Map(length int, cb func(i int) Node) []Node { + var nodes []Node + for i := 0; i < length; i++ { + nodes = append(nodes, cb(i)) + } + return nodes +}