mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-05 16:56:57 +08:00
21 lines
611 B
Go
21 lines
611 B
Go
package goquery
|
|
|
|
// Each() iterates over a Selection object, executing a function for each
|
|
// matched element.
|
|
func (this *Selection) Each(f func(int, *Selection)) *Selection {
|
|
for i, n := range this.Nodes {
|
|
f(i, newSingleSelection(n, this.document))
|
|
}
|
|
return this
|
|
}
|
|
|
|
// Map() passes each element in the current matched set through a function,
|
|
// producing a slice of string holding the returned values.
|
|
func (this *Selection) Map(f func(int, *Selection) string) (result []string) {
|
|
for i, n := range this.Nodes {
|
|
result = append(result, f(i, newSingleSelection(n, this.document)))
|
|
}
|
|
|
|
return result
|
|
}
|