v2

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[T any](itr Iterator[T]) ([]T, error)

Collect collects an interator into a slice. It uses CollectInto with a new slice

func CollectInto

func CollectInto[T any](itr Iterator[T], into []T) ([]T, error)

CollectInto collects the elements of an iterator into a provided slice which is returned

func Identity

func Identity[A any](a A) A

general helper, in this case created for DedupeIter[T,T]

Types

type CancellableIter

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

func NewCancelableIter

func NewCancelableIter[T any](ctx context.Context, itr Iterator[T]) *CancellableIter[T]

func (*CancellableIter[T]) Err

func (cii *CancellableIter[T]) Err() error

func (*CancellableIter[T]) Next

func (cii *CancellableIter[T]) Next() bool

type CloseIter

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

func WithClose

func WithClose[T any](itr Iterator[T], close func() bool) *CloseIter[T]

func (*CloseIter[T]) Close

func (i *CloseIter[T]) Close() error

type CloseIterator

type CloseIterator[T any] interface {
	Iterator[T]
	Close() error
}

type CloseResetIterator

type CloseResetIterator[T any] interface {
	CloseIterator[T]
	ResetIterator[T]
}

type CloserIter

type CloserIter[T io.Closer] struct {
	Iterator[T]
}

func NewCloserIter

func NewCloserIter[T io.Closer](itr Iterator[T]) *CloserIter[T]

func (*CloserIter[T]) Close

func (i *CloserIter[T]) Close() error

type CountIterator

type CountIterator[T any] interface {
	Iterator[T]
	Count() int
}

type CounterIter

type CounterIter[T any] struct {
	Iterator[T] // the underlying iterator
	// contains filtered or unexported fields
}

func NewCounterIter

func NewCounterIter[T any](itr Iterator[T]) *CounterIter[T]

func (*CounterIter[T]) Count

func (it *CounterIter[T]) Count() int

func (*CounterIter[T]) Next

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

type DedupeIter

type DedupeIter[A, B any] struct {
	// contains filtered or unexported fields
}

DedupeIter is a deduplicating iterator which creates an Iterator[B] from a sequence of Iterator[A].

func NewDedupingIter

func NewDedupingIter[A, B any](
	eq func(A, B) bool,
	from func(A) B,
	merge func(A, B) B,
	itr PeekIterator[A],
) *DedupeIter[A, B]

func (*DedupeIter[A, B]) At

func (it *DedupeIter[A, B]) At() B

func (*DedupeIter[A, B]) Err

func (it *DedupeIter[A, B]) Err() error

func (*DedupeIter[A, B]) Next

func (it *DedupeIter[A, B]) Next() bool

type EmptyIter

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

func NewEmptyIter

func NewEmptyIter[T any]() *EmptyIter[T]

func (*EmptyIter[T]) At

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

func (*EmptyIter[T]) Err

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

func (*EmptyIter[T]) Next

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

func (*EmptyIter[T]) Peek

func (it *EmptyIter[T]) Peek() (T, bool)

func (*EmptyIter[T]) Remaining

func (it *EmptyIter[T]) Remaining() int

func (*EmptyIter[T]) Reset

func (it *EmptyIter[T]) Reset()

noop

type FilterIter

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

func NewFilterIter

func NewFilterIter[T any](it Iterator[T], p Predicate[T]) *FilterIter[T]

func (*FilterIter[T]) Next

func (i *FilterIter[T]) Next() bool

type Iterator

type Iterator[T any] interface {
	Next() bool
	Err() error
	At() T
}

Iterator is the basic iterator type with the common functions for advancing and retrieving the current value.

General usage of the iterator:

for it.Next() {
    curr := it.At()
    // do something
}
if it.Err() != nil {
    // do something
}

type MapIter

type MapIter[A any, B any] struct {
	Iterator[A]
	// contains filtered or unexported fields
}

func NewMapIter

func NewMapIter[A any, B any](src Iterator[A], f func(A) B) *MapIter[A, B]

func (*MapIter[A, B]) At

func (it *MapIter[A, B]) At() B

type Ord

type Ord byte
const (
	Less Ord = iota
	Eq
	Greater
)

type Orderable

type Orderable[T any] interface {
	// Return the caller's position relative to the target
	Compare(T) Ord
}

type OrderedImpl

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

func NewOrderable

func NewOrderable[T any](val T, cmp func(T, T) Ord) OrderedImpl[T]

convenience method for creating an Orderable implementation for a type dynamically by passing in a value and a comparison function This is useful for types that are not under our control, such as built-in types and for reducing boilerplate in testware/etc. Hot-path code should use a statically defined Orderable implementation for performance

func (OrderedImpl[T]) Compare

func (o OrderedImpl[T]) Compare(other OrderedImpl[T]) Ord

func (OrderedImpl[T]) Unwrap

func (o OrderedImpl[T]) Unwrap() T

type PeekCloseIter

type PeekCloseIter[T any] struct {
	*PeekIter[T]
	// contains filtered or unexported fields
}

func NewPeekCloseIter

func NewPeekCloseIter[T any](itr CloseIterator[T]) *PeekCloseIter[T]

func (*PeekCloseIter[T]) Close

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

type PeekCloseIterator

type PeekCloseIterator[T any] interface {
	PeekIterator[T]
	CloseIterator[T]
}

type PeekIter

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

func NewPeekIter

func NewPeekIter[T any](itr Iterator[T]) *PeekIter[T]

func (*PeekIter[T]) At

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

func (*PeekIter[T]) Err

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

func (*PeekIter[T]) Next

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

func (*PeekIter[T]) Peek

func (it *PeekIter[T]) Peek() (T, bool)

type PeekIterator

type PeekIterator[T any] interface {
	Iterator[T]
	Peek() (T, bool)
}

type Predicate

type Predicate[T any] func(T) bool

type ResetIterator

type ResetIterator[T any] interface {
	Reset() error
	Iterator[T]
}

type SeekIterator

type SeekIterator[K, V any] interface {
	Iterator[V]
	Seek(K) error
}

type SizedIterator

type SizedIterator[T any] interface {
	Iterator[T]
	Remaining() int // remaining
}

type SliceIter

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

func NewSliceIter

func NewSliceIter[T any](xs []T) *SliceIter[T]

func (*SliceIter[T]) At

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

func (*SliceIter[T]) Err

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

func (*SliceIter[T]) Next

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

func (*SliceIter[T]) Remaining

func (it *SliceIter[T]) Remaining() int

type UnlessIterator

type UnlessIterator[T Orderable[T]] struct {
	// contains filtered or unexported fields
}

func NewUnlessIterator

func NewUnlessIterator[T Orderable[T]](a, b Iterator[T]) *UnlessIterator[T]

Iterators _must_ be sorted. Defers to underlying `PeekingIterator` implementation for both iterators if they implement it.

func (*UnlessIterator[T]) At

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

func (*UnlessIterator[T]) Err

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

func (*UnlessIterator[T]) Next

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

Jump to

Keyboard shortcuts

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