all repos — homestead @ e156f6a6d858b9d1f98e62bdfa584a7a72a9ff0c

Code for my website

Use gomponent's MapMap function

Alan Pearce
commit

e156f6a6d858b9d1f98e62bdfa584a7a72a9ff0c

parent

6cf5ef68ad0d4322caf0f1716ed3a4367fdc6582

1 file changed, 1 insertion(+), 11 deletions(-)

jump to
M templates/layout.gotemplates/layout.go
@@ -22,16 +22,6 @@ TitleAttrs Attrs
BodyAttrs Attrs } -// Map a map of anything to a [Group] (which is just a slice of [Node]-s). -func MapMap[K comparable, T any](ts map[K]T, cb func(K, T) g.Node) g.Group { - nodes := make([]g.Node, 0, len(ts)) - for k, t := range ts { - nodes = append(nodes, cb(k, t)) - } - - return nodes -} - func extendAttrs(base Attrs, attrs Attrs) g.Node { m := base for key, value := range attrs {
@@ -42,7 +32,7 @@ m[key] = value
} } - return MapMap(m, func(k string, v string) g.Node { + return g.MapMap(m, func(k string, v string) g.Node { return g.Attr(k, v) // can't inline this because it uses ...value, grr }) }