streams

package
v0.0.0-...-cb92b4e Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MPL-2.0 Imports: 4 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[T any](ctx context.Context, it Iterator[T], max int) (ret []T, _ error)

Collect is used to collect all of the items from an Iterator. If more than max elements are emitted, then Collect will return an error.

func EOS

func EOS() error

EOS returns a new EndOfStream error

func First

func First[T any](ctx context.Context, it Iterator[T]) (maybe.Maybe[T], error)

First returns (Just, nil) when the stream produces the next element or (Nothing, nil) if the stream is over. First returns (Nothing, err) if it encouters any error.

func ForEach

func ForEach[T any](ctx context.Context, it Iterator[T], fn func(T) error) error

ForEach calls fn for each element of it. fn must not retain dst, between calls.

func IsEOS

func IsEOS(err error) bool

IsEOS returns true if the error is an EndOfStream error

func Last

func Last[T any](ctx context.Context, it Iterator[T]) (last maybe.Maybe[T], _ error)

Last returns the last element that the stream produces.

func LoadChan

func LoadChan[T any](ctx context.Context, it Iterator[T], out chan<- T) error

LoadChan loads a channel from an Iterator. If the context is cancelled, LoadChan returns that error. If it.Next errors other than EOS, LoadChan returns that error.

func Next

func Next[T any](ctx context.Context, it Iterator[T]) (T, error)

Next returns a new T instead of writing it to a pointer destination. It calls it.Next on the Iterator

func Peek

func Peek[T any](ctx context.Context, it Peekable[T]) (T, error)

Peek return a new T instead of writing it to a pointer destination. It calls it.Peek on the Iterator.

func ReadFull

func ReadFull[T any](ctx context.Context, it Iterator[T], buf []T) (int, error)

ReadFull copies elements from the iterator into buf. ReadFull returns EOS when the iterator is empty.

Types

type Batcher

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

func NewBatcher

func NewBatcher[T any](inner Iterator[T], min int, dur time.Duration) *Batcher[T]

func (*Batcher[T]) Next

func (b *Batcher[T]) Next(ctx context.Context, dst *[]T) error

type Chan

type Chan[T any] <-chan T

Chan implements a stream backed by a channel

func (Chan[T]) Next

func (c Chan[T]) Next(ctx context.Context, dst *T) error

type EndOfStream

type EndOfStream struct{}

EndOfStream is returned by Next and Seek to indicate that the stream has no more elements.

func (EndOfStream) Error

func (EndOfStream) Error() string

type Iterator

type Iterator[T any] interface {
	// Next advances the iterator and reads the next element into dst
	Next(ctx context.Context, dst *T) error
}

func Concat

func Concat[T any](its ...Iterator[T]) Iterator[T]

func NewFilter

func NewFilter[T any](x Iterator[T], pred func(T) bool) Iterator[T]

type Peekable

type Peekable[T any] interface {
	Iterator[T]

	// Peek shows the next element of the Iterator without changing the state of the Iterator
	Peek(ctx context.Context, dst *T) error
}

Peekable is an Iterator which also has the Peek method

type Reader

type Reader[T any] interface {
	Read(ctx context.Context, dst []T) (int, error)
}

Reader contains the Read method

type Seeker

type Seeker[T any] interface {
	// Seek ensures that all future elements of the iterator will be >= gteq
	Seek(ctx context.Context, gteq T) error
}

Seeker contains the Seek method

type Slice

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

func NewSlice

func NewSlice[T any](xs []T, cp func(*T, T)) *Slice[T]

func (*Slice[T]) Next

func (it *Slice[T]) Next(ctx context.Context, dst *T) error

func (*Slice[T]) Reset

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

Jump to

Keyboard shortcuts

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