Documentation
¶
Overview ¶
Package iterx provides convenience functions for iterators.
Index ¶
- func CSVFile(file string, fn func(*csv.Reader)) iter.Seq2[[]string, error]
- func CSVReader(r io.Reader, fn func(*csv.Reader)) iter.Seq2[[]string, error]
- func CollectErr[T any](it iter.Seq2[T, error]) ([]T, error)
- func ISlice[T any](s []T) iter.Seq2[int, T]
- func Limit[T any](it iter.Seq[T], n int) iter.Seq[T]
- func Limit2[T any, S any](it iter.Seq2[T, S], n int) iter.Seq2[T, S]
- func LinesFile(file string) iter.Seq2[string, error]
- func LinesReader(r io.Reader) iter.Seq2[string, error]
- func Skip[T any](it iter.Seq[T], n int) iter.Seq[T]
- func Skip2[T any, S any](it iter.Seq2[T, S], n int) iter.Seq2[T, S]
- func Slice[T any](s []T) iter.Seq[T]
- type Unreader
- type Unreader2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CSVFile ¶
CSVFile iterates over CSV entries from a file. fn is an optional function for modifying the CSV parser, for example for changing the delimiter.
func CSVReader ¶
CSVReader iterates over CSV entries from a reader. fn is an optional function for modifying the CSV parser, for example for changing the delimiter.
func CollectErr ¶ added in v1.1.0
CollectErr collects the given T's in a slice until the error is non-nil.
func ISlice ¶
ISlice returns an iterator over the slice values and their indices, like in a range expression.
func Limit ¶
Limit returns an iterator that stops after n elements, if the underlying iterator does not stop before.
func Limit2 ¶
Limit2 returns an iterator that stops after n elements, if the underlying iterator does not stop before.
func LinesReader ¶
LinesReader iterates over text lines from a reader.
Types ¶
type Unreader ¶ added in v0.6.0
type Unreader[T any] struct { // contains filtered or unexported fields }
An Unreader wraps an iterator and adds an unread function.
func NewUnreader ¶ added in v0.6.0
NewUnreader returns an Unreader with seq as its underlying iterator.
func (*Unreader[T]) GroupBy ¶ added in v0.6.0
GroupBy returns an iterator over groups, where each group is an iterator that yields elements as long as the elements have sameGroup==true with the first element in the group.
func (*Unreader[T]) Read ¶ added in v0.6.0
Read returns the result of calling the underlying reader, or the last unread element.
type Unreader2 ¶ added in v0.6.0
type Unreader2[T, S any] struct { // contains filtered or unexported fields }
An Unreader2 wraps an iterator and adds an unread function.
func NewUnreader2 ¶ added in v0.6.0
NewUnreader2 returns an Unreader2 with seq as its underlying iterator.
func (*Unreader2[T, S]) GroupBy ¶ added in v0.6.0
func (r *Unreader2[T, S]) GroupBy( sameGroup func(oldT T, oldS S, newT T, newS S) bool, ) iter.Seq[iter.Seq2[T, S]]
GroupBy returns an iterator over groups, where each group is an iterator that yields elements as long as the elements have sameGroup==true with the first element in the group.
func (*Unreader2[T, S]) Read ¶ added in v0.6.0
Read returns the result of calling the underlying reader, or the last unread element.