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-seqs
Import 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.