Documentation
¶
Index ¶
- func All[T any](it Iter[T]) ([]T, error)
- func AllCtx[T any](ctx context.Context, it IterCtx[T]) ([]T, error)
- func AllPages[T any](ctx context.Context, it PageIter[T]) ([]T, error)
- func AsSeq[T any](it Iter[T]) iter.Seq[T]
- func AsSeqErr[T any](it Iter[T]) iter.Seq2[T, error]
- func Encode[T any](enc Encoder, it Iter[T]) error
- type Decoder
- type Encoder
- type Iter
- func Decode[T any](dec Decoder) Iter[T]
- func Filter[T any](it Iter[T], filter func(v T) bool) Iter[T]
- func FromRows[T any](rows RowsScanner, scan func() (T, error)) Iter[T]
- func Join[T any](sub ...Iter[T]) Iter[T]
- func Limit[T any](it Iter[T], limit int) Iter[T]
- func Map[T1 any, T2 any](it Iter[T1], conv func(v T1) (T2, error)) Iter[T2]
- func MultiIter[T any](strict bool, sub ...Iter[T]) Iter[T]
- func PagesAsIter[T any](ctx context.Context, it PageIter[T]) Iter[T]
- func Seq[T any](it iter.Seq[T]) Iter[T]
- func SeqErr[T any](it iter.Seq2[T, error]) Iter[T]
- type IterCtx
- func FilterCtx[T any](it IterCtx[T], filter func(v T) bool) IterCtx[T]
- func JoinCtx[T any](sub ...IterCtx[T]) IterCtx[T]
- func MapCtx[T1 any, T2 any](it IterCtx[T1], conv func(ctx context.Context, v T1) (T2, error)) IterCtx[T2]
- func MultiIterCtx[T any](strict bool, sub ...IterCtx[T]) IterCtx[T]
- func PagesAsIterCtx[T any](it PageIter[T]) IterCtx[T]
- type PageIter
- func FilterPage[T any](it PageIter[T], filter func(v T) bool) PageIter[T]
- func IterWithPage[T any](it Iter[T], page int) PageIter[T]
- func IterWithPageCtx[T any](it IterCtx[T], page int) PageIter[T]
- func JoinPages[T any](sub ...PageIter[T]) PageIter[T]
- func MapPage[T1 any, T2 any](it PageIter[T1], conv func(ctx context.Context, v T1) (T2, error)) PageIter[T2]
- func MultiPageIter[T any](strict bool, sub ...PageIter[T]) PageIter[T]
- func PageSlice[T any](s [][]T) PageIter[T]
- func SeqErrPages[T any](it iter.Seq2[[]T, error]) PageIter[T]
- func SeqPages[T any](it iter.Seq[[]T]) PageIter[T]
- type PagedIter
- type RowsScanner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsSeq ¶ added in v1.1.0
AsSeq returns a sequence of results. It stops if an error is encountered.
Types ¶
type Iter ¶
type Iter[T any] interface { // Next returns the next item. // It returns io.EOF if there are no more items left. Next() (T, error) // Close the iterator. Close() }
Iter is a generic interface for the iterator.
Example:
defer it.Close()
for {
v, err := it.Next()
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
fmt.Println(v)
}
func Decode ¶
Decode an iterator.
It will use type T as a destination type, thus it must not be an interface.
func Filter ¶
Filter iterator results with a function. If function returns false, result is skipped.
func FromRows ¶ added in v1.2.0
func FromRows[T any](rows RowsScanner, scan func() (T, error)) Iter[T]
FromRows converts sql.Rows to Iter.
func Join ¶
Join iterators by listing elements sequentially from each iterator in order. If any of the iterators fail, an error is returned.
func Limit ¶ added in v1.1.0
Limit the number of results returned by the iterator. It returns all results if limit < 0.
func MultiIter ¶
MultiIter creates a new iterator that alternates between results from sub iterators.
If strict is set to true, the iterator will fail on the first non io.EOF error. If it's false, the iterator will return the last error when all iterators are done (or fail).
func PagesAsIter ¶
PagesAsIter takes a PageIter and converts it to an Iter.
type IterCtx ¶
type IterCtx[T any] interface { // NextCtx returns the next item. // It returns io.EOF if there are no more items left. NextCtx(ctx context.Context) (T, error) // Close the iterator. Close() }
IterCtx is a generic interface for the iterator with a context.
Example:
defer it.Close()
for {
v, err := it.NextCtx(ctx)
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
fmt.Println(v)
}
func FilterCtx ¶
FilterCtx filters iterator results with a function. If function returns false, result is skipped.
func JoinCtx ¶
JoinCtx iterators by listing elements sequentially from each iterator in order. If any of the iterators fail, an error is returned.
func MapCtx ¶
func MapCtx[T1 any, T2 any](it IterCtx[T1], conv func(ctx context.Context, v T1) (T2, error)) IterCtx[T2]
MapCtx maps iterator items to a different type.
func MultiIterCtx ¶
MultiIterCtx creates a new iterator that alternates between results from sub iterators.
If strict is set to true, the iterator will fail on the first non io.EOF error. If it's false, the iterator will return the last error when all iterators are done (or fail).
func PagesAsIterCtx ¶
PagesAsIterCtx takes a PageIter and converts it to an IterCtx.
type PageIter ¶
type PageIter[T any] interface { // NextPage returns the next page of items. // It returns io.EOF if there are no more items left. NextPage(ctx context.Context) ([]T, error) // Close the iterator. Close() }
PageIter is an iterator that iterates over pages of items.
func FilterPage ¶
FilterPage filters page iterator results with a function. If function returns false, result is skipped.
func IterWithPage ¶
IterWithPage takes an Iter and converts it to an PageIter with a specific page size.
func IterWithPageCtx ¶
IterWithPageCtx takes an IterCtx and converts it to an PageIter with a specific page size.
func JoinPages ¶
JoinPages joins iterators by listing pages sequentially from each iterator in order. If any of the iterators fail, an error is returned.
func MapPage ¶
func MapPage[T1 any, T2 any](it PageIter[T1], conv func(ctx context.Context, v T1) (T2, error)) PageIter[T2]
MapPage maps page iterator items to a different type.
func MultiPageIter ¶
MultiPageIter creates a new iterator that alternates between pages from sub iterators.
If strict is set to true, the iterator will fail on the first non io.EOF error. If it's false, the iterator will return the last error when all iterators are done (or fail).
func SeqErrPages ¶ added in v1.1.0
SeqErrPages creates an iterator from a sequence of pages and errors.
type PagedIter ¶
PagedIter combines Iter and PageIter.
type RowsScanner ¶ added in v1.2.0
RowsScanner is a minimal interface that sql.Rows implements.