go-seqs is a library for working with sequence-like data in Go, taking advantage of generics introduced in Go 1.18.
Add the library as a dependency:
go get github.com/siliconbrain/go-seqsImport it into your code:
import "github.com/siliconbrain/go-seqs/seqs"Use to your heart's delight!
Comparision with iter
The iter package defines Seq as
type Seq[V any] func(yield func(V) bool)which unfortunately means no non-trivial methods can be defined on implementations.
Meanwhile, implementations of our seqs.Seq interface can also implement any other interface, e.g. optional length queries via seqs.Lener/seqs.FiniteSeq.
Unfortunately, seqs.Seq is not directly compatible with iter.Seq since yield's return value's meaning is inverted.