Documentation ¶
Overview ¶
Package stream contains interfaces and helper functions for managing iterators that can block.
Index ¶
- func Collect[T any](ctx context.Context, it Iterator[T], max int) (ret []T, _ error)
- func CopyMerged[T any](dst, src *Merged[T])
- func EOS() error
- func ForEach[T any](ctx context.Context, it Iterator[T], fn func(t T) error) error
- func IsEOS(err error) bool
- func Next[T any](ctx context.Context, it Iterator[T]) (ret T, _ error)
- func Peek[T any](ctx context.Context, it Peekable[T]) (ret T, _ error)
- func Read[T any](ctx context.Context, it Iterator[T], buf []T) (n int, _ error)
- func Skip[T any](ctx context.Context, it Iterator[T]) error
- type CompareFunc
- type Iterator
- type Merged
- type Merger
- type Ordered
- type Peekable
- type PriorityQueue
- type Slice
- type Stream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyMerged ¶
CopyMerged efficiently copies a Merged from src to dst.
func ForEach ¶
ForEach calls fn with elements from it. The element passed to fn must not be retained after fn has returned.
func Next ¶
Next is a convenience function for allocating a T and using the iterator to read into it with it.Next
func Peek ¶
Peek is a convenience function for allocating a T and using the iterator to read into it with it.Peek
Types ¶
type CompareFunc ¶
CompareFunc is a comparision function for two streams. DEPRECATED
type Iterator ¶
type Merged ¶
type Merged[T any] struct { // Values is a slice of values, which are not ordered relative to one another. Values []T // Indexes is the index of the stream that produced each value. Indexes []int }
Merged is the type of elements emitted by the Merger Iterator
type Merger ¶
type Merger[T any] struct { // contains filtered or unexported fields }
type Ordered ¶
type Ordered[T any] struct { // contains filtered or unexported fields }
Ordered enforces ascending order or returns an error
func NewOrdered ¶
type Peekable ¶
type Peekable[T any] interface { Iterator[T] // Peek reads the next element into dst, but does not advance the iterator. // Peek returns EOS when the iteration is over, dst will not be affected. Peek(ctx context.Context, dst *T) error }
func NewPeekable ¶
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
PriorityQueue implements a priority queue that operates on streams. DEPRECATED: use Merger instead
func NewPriorityQueue ¶
func NewPriorityQueue(ss []Stream, cmp CompareFunc) *PriorityQueue
NewPriorityQueue creates a new priority queue. DEPRECATED: use Merger instead