Implement Selection.Map by calling the generic Map

Tests pass and verified that benchmarks are basically the same,
including memory allocation.
This commit is contained in:
Martin Angers
2024-02-22 17:08:26 -05:00
parent de2d209e9e
commit 1fad3d426b
+4 -7
View File
@@ -31,18 +31,15 @@ func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection {
// element in that selection starting at 0, and a *Selection that contains
// only that element.
func (s *Selection) Map(f func(int, *Selection) string) (result []string) {
for i, n := range s.Nodes {
result = append(result, f(i, newSingleSelection(n, s.document)))
}
return result
return Map(s, f)
}
// Generic version of Selection.Map, allowing any type to be returned.
// Map is the generic version of Selection.Map, allowing any type to be
// returned.
func Map[E any](s *Selection, f func(int, *Selection) E) (result []E) {
for i, n := range s.Nodes {
result = append(result, f(i, newSingleSelection(n, s.document)))
}
return result
}
}