From aeecb06b1e04a72e7d3312468c5b92f6bb2f3459 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Thu, 26 May 2016 08:12:20 -0400 Subject: [PATCH] doc: better explain the arguments to the function passed to Each and Map, closes #107 --- iteration.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/iteration.go b/iteration.go index 6b68018..e246f2e 100644 --- a/iteration.go +++ b/iteration.go @@ -1,7 +1,10 @@ package goquery // Each iterates over a Selection object, executing a function for each -// matched element. It returns the current Selection object. +// matched element. It returns the current Selection object. The function +// f is called for each element in the selection with the index of the +// element in that selection starting at 0, and a *Selection that contains +// only that element. func (s *Selection) Each(f func(int, *Selection)) *Selection { for i, n := range s.Nodes { f(i, newSingleSelection(n, s.document)) @@ -23,7 +26,10 @@ func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection { } // Map passes each element in the current matched set through a function, -// producing a slice of string holding the returned values. +// producing a slice of string holding the returned values. The function +// f is called for each element in the selection with the index of the +// 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)))