1 Star 2 Fork 1

GoLangLibs / goquery

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
iteration.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
Martin Angers 提交于 2013-05-24 11:25 . add EachWithBreak(), fixes #13
package goquery
// Each() iterates over a Selection object, executing a function for each
// matched element. It returns the current Selection object.
func (this *Selection) Each(f func(int, *Selection)) *Selection {
for i, n := range this.Nodes {
f(i, newSingleSelection(n, this.document))
}
return this
}
// EachWithBreak() iterates over a Selection object, executing a function for each
// matched element. It is identical to `Each()` except that it is possible to break
// out of the loop by returning `false` in the callback function. It returns the
// current Selection object.
func (this *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection {
for i, n := range this.Nodes {
if !f(i, newSingleSelection(n, this.document)) {
return this
}
}
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/GoLangLibs/goquery.git
git@gitee.com:GoLangLibs/goquery.git
GoLangLibs
goquery
goquery
v0.3.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891