goquery
goquery copied to clipboard
Question: Is it possible support the iterator in version 1.23?
Golang 1.23 will support the iter
package and define the types iter.Seq
and iter.Seq2
as iterators. My idea is that maybe Each
can return an iterator. Then the user can use the for loop
on it easily.
func (s *Selection) EachIter() iter.Seq2[int, *Selection]
At client side:
for i, s := range doc.Find(".left-content article .post-title").Each() {
title := s.Find("a").Text()
fmt.Printf("Review %d: %s\n", i, title)
}
Reference
https://tip.golang.org/doc/go1.23 https://pkg.go.dev/iter@master