Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoMoreItems = errors.New("no more items")
Functions ¶
Types ¶
type DeduplicatingIterator ¶
type DeduplicatingIterator[T any, Id comparable] struct { // contains filtered or unexported fields }
func NewDedupeIterator ¶
func NewDedupeIterator[T any, Id comparable](it Iterator[T], getId func(T) Id) *DeduplicatingIterator[T, Id]
type Iterator ¶
type Iterator[T any] interface { // HasNext returns true if there are more items to iterate over. HasNext // will also return true if the iterator needs to fetch the next page of // items from the underlying source and the request fails, even if there // are no more items to iterate over. In this case, Next will return the // error. HasNext(context.Context) bool // Next returns the next item in the iterator. If there are no more items // to iterate over, it returns ErrNoMoreItems. If there was an error // fetching the next page of items, it returns that error. Once Next // returns ErrNoMoreItems or an error, it will continue to return that // error. Next(context.Context) (T, error) }
Iterator[T] is an iterator over items of type T. It is similar to java.util.Iterator. It is not thread-safe.
type PaginatingIterator ¶
type PaginatingIterator[Req, Resp, T any] struct { // contains filtered or unexported fields }
Use struct{} for Req for iterators that don't need any request structure.
func NewIterator ¶
func NewIterator[Req, Resp, T any]( nextReq *Req, getNextPage func(context.Context, Req) (Resp, error), getItems func(Resp) []T, getNextReq func(Resp) *Req, ) *PaginatingIterator[Req, Resp, T]
Returns a new iterator. The iterator will fetch the next page of items lazily, when needed. nextReq is the request to be used to fetch the initial page. If nil, then no page will be fetched. getNextPage fetches the next page of items, returning the deserialized response and error. getItems selects the items being iterated over from the response. getNextReq is used to get the next request to be used in the next page. If the returned value is nil, then there is no next page to fetch.
type SliceIterator ¶ added in v0.29.1
type SliceIterator[T any] []T
A simple iterator over a slice.