iterator

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect[T interface{}](it Iterator[T]) ([]T, error)

Types

type Iterator

type Iterator[T interface{}] interface {
	// Next returns the next item, or an error. All errors are terminal; no more values
	// will arrive after the first error.
	Next() (T, error)

	// Close the consumer side of the Iterator. Must always be called when
	// the iterator is no longer used, to release resources.
	Close()
}

Iterator is a generic interface for streaming a series of item, with support for back-pressure.

func Filter

func Filter[T interface{}](it Iterator[T], f func(T) bool) Iterator[T]

func FromList

func FromList[T interface{}](ts []T) Iterator[T]

func Map

func Map[F, T interface{}](it Iterator[F], f MapFunc[F, T]) Iterator[T]

func NewBuffer

func NewBuffer[T interface{}](it Iterator[T], bufferSize int) Iterator[T]

type MapFunc

type MapFunc[F, T interface{}] func(F) (T, error)

type Producer

type Producer[T interface{}] struct {
	// contains filtered or unexported fields
}

func NewBufferedProducer

func NewBufferedProducer[T interface{}](bufferSize int) *Producer[T]

func NewProducer

func NewProducer[T interface{}]() *Producer[T]

func (*Producer[T]) Close

func (p *Producer[T]) Close()

func (*Producer[T]) Done

func (p *Producer[T]) Done()

func (*Producer[T]) Error

func (p *Producer[T]) Error(err error)

Error closes the producer with the provided error. If the error is `nil`, io.EOF will be used instead to indicate a nice close.

func (*Producer[T]) Next

func (p *Producer[T]) Next() (T, error)

func (*Producer[T]) Value

func (p *Producer[T]) Value(t T) error

Value adds a new value to the iterator. This method will block until the consumer has read out the value or the iterator is closed. The returning error should be read, as an error indicates no more values can be written to the producer.

Jump to

Keyboard shortcuts

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