From 1fad3d426b1d8edf74ad4e02c286c5761779c6e5 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Thu, 22 Feb 2024 17:08:26 -0500 Subject: [PATCH] Implement Selection.Map by calling the generic Map Tests pass and verified that benchmarks are basically the same, including memory allocation. --- iteration.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/iteration.go b/iteration.go index 64dc5a2..160fa90 100644 --- a/iteration.go +++ b/iteration.go @@ -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 -} \ No newline at end of file +}