stream

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package stream is a library of generic types designed to work on streams of values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy[T any](w Writer[T], r Reader[T]) (int64, error)

Copy writes values read from r to w, returning the number of values written and any error other than io.EOF.

func ReadAll

func ReadAll[T any](r Reader[T]) ([]T, error)

ReadAll reads all values from r and returns them as a slice, along with any error that occurred (other than io.EOF).

func ReadAtLeast

func ReadAtLeast[T any](r Reader[T], buf []T, min int) (n int, err error)

func ReadFull

func ReadFull[T any](r Reader[T], buf []T) (int, error)

func Seek

func Seek(offset, length, seek int64, whence int) (int64, error)

func Values

func Values[T any](it *Iterator[T]) ([]T, error)

Types

type Iterator

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

func Iter

func Iter[T any](r Reader[T]) *Iterator[T]

func (*Iterator[T]) Err

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

func (*Iterator[T]) Next

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

func (*Iterator[T]) Reset

func (it *Iterator[T]) Reset(r Reader[T])

func (*Iterator[T]) Value

func (it *Iterator[T]) Value() T

type Optional

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

func Opt

func Opt[T any](val T, err error) Optional[T]

func (Optional[T]) Value

func (opt Optional[T]) Value() (T, error)

type ReadCloser

type ReadCloser[T any] interface {
	Reader[T]
	io.Closer
}

ReadCloser represents a closable stream of values of T.

ReadClosers is like io.ReadCloser for values of any type.

func ErrCloser

func ErrCloser[T any](err error) ReadCloser[T]

func NewReadCloser

func NewReadCloser[T any](r Reader[T], c io.Closer) ReadCloser[T]

NewReadCloser constructs a ReadCloser from the pair of r and c.

func NopCloser

func NopCloser[T any](r Reader[T]) ReadCloser[T]

NopCloser constructs a ReadCloser from a Reader.

type ReadSeekCloser

type ReadSeekCloser[T any] interface {
	Reader[T]
	io.Seeker
	io.Closer
}

type ReadSeeker

type ReadSeeker[T any] interface {
	Reader[T]
	io.Seeker
}

type Reader

type Reader[T any] interface {
	// Reads values from the stream, returning the number of values read and any
	// error that occurred.
	//
	// The error is io.EOF when the end of the stream has been reached.
	Read(values []T) (int, error)
}

Reader is an interface implemented by types that read a stream of values of type T.

func ChanReader

func ChanReader[T any](ch <-chan Optional[T]) Reader[T]

func ConvertReader

func ConvertReader[To, From any](base Reader[From], conv func(From) (To, error)) Reader[To]

func MultiReader

func MultiReader[T any](readers ...Reader[T]) Reader[T]

func NewReader

func NewReader[T any](values ...T) Reader[T]

NewReader constructs a Reader from a sequence of values.

func ReaderFunc

func ReaderFunc[T any](f func([]T) (int, error)) Reader[T]

type WriteCloser

type WriteCloser[T any] interface {
	Writer[T]
	io.Closer
}

WriteCloser represents a closable stream of values of T.

WriteClosers is like io.WriteCloser for values of any type.

func NewWriteCloser

func NewWriteCloser[T any](w Writer[T], c io.Closer) WriteCloser[T]

type Writer

type Writer[T any] interface {
	Write(values []T) (int, error)
}

Writer is an interface implemented by types that write a stream of values of type T.

func ConvertWriter

func ConvertWriter[To, From any](base Writer[To], conv func(From) (To, error)) Writer[From]

Jump to

Keyboard shortcuts

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