github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/goquery/iteration.go (about) 1 package goquery 2 3 // Each() iterates over a Selection object, executing a function for each 4 // matched element. It returns the current Selection object. 5 func (this *Selection) Each(f func(int, *Selection)) *Selection { 6 for i, n := range this.Nodes { 7 f(i, newSingleSelection(n, this.document)) 8 } 9 return this 10 } 11 12 // EachWithBreak() iterates over a Selection object, executing a function for each 13 // matched element. It is identical to `Each()` except that it is possible to break 14 // out of the loop by returning `false` in the callback function. It returns the 15 // current Selection object. 16 func (this *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection { 17 for i, n := range this.Nodes { 18 if !f(i, newSingleSelection(n, this.document)) { 19 return this 20 } 21 } 22 return this 23 } 24 25 // Map() passes each element in the current matched set through a function, 26 // producing a slice of string holding the returned values. 27 func (this *Selection) Map(f func(int, *Selection) string) (result []string) { 28 for i, n := range this.Nodes { 29 result = append(result, f(i, newSingleSelection(n, this.document))) 30 } 31 32 return result 33 }