Documentation
¶
Index ¶
- func Reduce[T any, V any](ctx context.Context, it Iterator[T], reducer func(V, T) (V, error)) (ret V, err error)
- func ToSlice[T any](ctx context.Context, it Iterator[T]) ([]T, error)
- type Iterator
- func Aggregate[T any](its ...Iterator[T]) Iterator[T]
- func Empty[T any]() Iterator[T]
- func Error[T any](err error) Iterator[T]
- func Filter[T any](it Iterator[T], fn func(T) bool) Iterator[T]
- func FromDocumentIterator[T any](it storageapi.Iterator) Iterator[T]
- func FromFunc[T any](fn func(context.Context) (T, bool, error), close func() error) Iterator[T]
- func FromSlice[T any](els []T) Iterator[T]
- func IsEmpty[T any](ctx context.Context, i Iterator[T]) (Iterator[T], bool)
- func Map[T any, V any](it Iterator[T], fn func(T) V) Iterator[V]
- func Unslice[T any](it Iterator[[]T]) Iterator[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Iterator ¶
type Iterator[T any] interface { // Next returns the next element and true or nil and false // if there's no more elements in this Iterator. Err should be // checked for any errors incurred during the lifecycle of this Iterator. // Note that if an error is found, it's up to the implementation as to // whether to return false and stop iteration or aggregate errors // and return at the end. // // This method blocks until data is available. Implementations should // use the given context's Done channel to know when data is no longer // required and so the call should return. Next(context.Context) (T, bool) // Err returns the first error or an aggreation of the errors // encountered by the Iterator. Err() error io.Closer }
Iterator provides a convenient interface for iterating over chunks of structured or unstructured data such as a file of newline-delimited lines of text or a set of datastore documents.
func Aggregate ¶
Aggregate combines multiple iterators of T into one single iterator of T. If its is nil or empty, this method safely returns an empty iterator.
func Error ¶
Error returns an Iterator of T that never returns a value and always returns the given error.
func Filter ¶
Filter wraps an iterator of type T and returns another iterator that will apply fn to each of the elements produced and filter out any elements for which fn returns false.
func FromDocumentIterator ¶
func FromDocumentIterator[T any](it storageapi.Iterator) Iterator[T]
FromDocumentIterator maps a storageapi.Iterator to an Iterator of type T.
func IsEmpty ¶
IsEmpty consumes the first element in i and returns true if it is empty or false if not and returns a new iterator that should be used instead of i.
The given iterator is consumed in either case, so its Close method is wrapped with the returned iterator, or if the given iterator is empty, its Close method is called for the caller, so it's safe to override the variable holding the passed iterator with the return value of this function.