Skip to content

Commit 1fad3d4

Browse files
committed
Implement Selection.Map by calling the generic Map
Tests pass and verified that benchmarks are basically the same, including memory allocation.
1 parent de2d209 commit 1fad3d4

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

iteration.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@ func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection {
3131
// element in that selection starting at 0, and a *Selection that contains
3232
// only that element.
3333
func (s *Selection) Map(f func(int, *Selection) string) (result []string) {
34-
for i, n := range s.Nodes {
35-
result = append(result, f(i, newSingleSelection(n, s.document)))
36-
}
37-
38-
return result
34+
return Map(s, f)
3935
}
4036

41-
// Generic version of Selection.Map, allowing any type to be returned.
37+
// Map is the generic version of Selection.Map, allowing any type to be
38+
// returned.
4239
func Map[E any](s *Selection, f func(int, *Selection) E) (result []E) {
4340
for i, n := range s.Nodes {
4441
result = append(result, f(i, newSingleSelection(n, s.document)))
4542
}
4643

4744
return result
48-
}
45+
}

0 commit comments

Comments
 (0)