iter

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustSlice added in v1.8.0

func MustSlice[T any](it Iterator[T]) []T

func ReadBatch

func ReadBatch[T any](ctx context.Context, iterator Iterator[T], batchSize int, fn func(context.Context, []T) error) error

ReadBatch reads profiles from the iterator in batches and call fn. If fn returns an error, the iteration is stopped and the error is returned. The array passed in fn is reused between calls, so it should be copied if needed.

func Slice

func Slice[T any](it Iterator[T]) ([]T, error)

Types

type AsyncBatchIterator added in v1.2.0

type AsyncBatchIterator[T, N any] struct {
	// contains filtered or unexported fields
}

func NewAsyncBatchIterator added in v1.2.0

func NewAsyncBatchIterator[T, N any](
	iterator Iterator[T],
	size int,
	clone func(T) N,
	release func([]N),
) *AsyncBatchIterator[T, N]

func (*AsyncBatchIterator[T, N]) At added in v1.2.0

func (x *AsyncBatchIterator[T, N]) At() N

func (*AsyncBatchIterator[T, N]) Close added in v1.2.0

func (x *AsyncBatchIterator[T, N]) Close() error

func (*AsyncBatchIterator[T, N]) Err added in v1.2.0

func (x *AsyncBatchIterator[T, N]) Err() error

func (*AsyncBatchIterator[T, N]) Next added in v1.2.0

func (x *AsyncBatchIterator[T, N]) Next() bool

type BufferedIterator

type BufferedIterator[T any] struct {
	Iterator[T]
	// contains filtered or unexported fields
}

func (*BufferedIterator[T]) At

func (it *BufferedIterator[T]) At() T

func (*BufferedIterator[T]) Close

func (it *BufferedIterator[T]) Close() error

func (*BufferedIterator[T]) Err

func (it *BufferedIterator[T]) Err() error

func (*BufferedIterator[T]) Next

func (it *BufferedIterator[T]) Next() bool

type Iterator

type Iterator[A any] interface {
	// Next advances the iterator and returns true if another value was found.
	Next() bool

	// At returns the value at the current iterator position.
	At() A

	// Err returns the last error of the iterator.
	Err() error

	Close() error
}

func CloneN

func CloneN[T any](it Iterator[T], n int) ([]Iterator[T], error)

CloneN returns N copy of the iterator. The returned iterators are independent of the original iterator. The original might be exhausted and should be discarded.

func NewBufferedIterator

func NewBufferedIterator[T any](it Iterator[T], size int) Iterator[T]

NewBufferedIterator returns an iterator that reads asynchronously from the given iterator and buffers up to size elements.

func NewEmptyIterator

func NewEmptyIterator[T any]() Iterator[T]

func NewErrIterator

func NewErrIterator[A any](err error) Iterator[A]

func NewSliceIndexIterator

func NewSliceIndexIterator[T constraints.Integer, M any](s []M, i Iterator[T]) Iterator[M]

func NewSliceIterator

func NewSliceIterator[A any](s []A) Iterator[A]

func NewUnionIterator

func NewUnionIterator[T any](iters ...Iterator[T]) Iterator[T]

func Tee added in v1.2.0

func Tee[T any](iter Iterator[T]) (a, b Iterator[T])

Tee returns 2 independent iterators from a single iterable.

The original iterator should not be used anywhere else, except that it's caller responsibility to close it and handle the error, after all the tee iterators finished.

Tee buffers source objects, and frees them eventually: when an object from the source iterator is consumed, the ownership is transferred to Tee. Therefore, the caller must ensure the source iterator never reuses objects returned with At.

Tee never blocks the leader iterator, instead, it grows the internal buffer: if any of the returned iterators are abandoned, all source iterator objects will be held in the buffer.

func TeeN added in v1.2.0

func TeeN[T any](iter Iterator[T], n int) []Iterator[T]

type SeekIterator

type SeekIterator[A any, B any] interface {
	Iterator[A]

	// Like Next but skips over results until reading >= the given location
	Seek(pos B) bool
}

func NewErrSeekIterator

func NewErrSeekIterator[A any, B any](err error) SeekIterator[A, B]

func NewSliceSeekIterator

func NewSliceSeekIterator[A constraints.Ordered](s []A) SeekIterator[A, A]

type TreeIterator

type TreeIterator[T any] struct {
	*loser.Tree[T, Iterator[T]]
}

func NewTreeIterator

func NewTreeIterator[T any](tree *loser.Tree[T, Iterator[T]]) *TreeIterator[T]

NewTreeIterator returns an Iterator that iterates over the given loser tree iterator.

func (TreeIterator[T]) At

func (it TreeIterator[T]) At() T

func (*TreeIterator[T]) Close

func (it *TreeIterator[T]) Close() error

func (*TreeIterator[T]) Err

func (it *TreeIterator[T]) Err() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL