Documentation ¶
Index ¶
- Variables
- func Collect[I any](ctx context.Context, stream Stream[I]) (slice []I, err error)
- type Mapper
- type Selector
- type Sizer
- type Stream
- func Delay[I any](source Stream[I], delay time.Duration) Stream[I]
- func Map[F, T any](source Stream[F], mapper Mapper[F, T]) Stream[T]
- func Null[I any]() Stream[I]
- func Pour[I any](slice ...I) Stream[I]
- func Repeat[I any](item I, times int) Stream[I]
- func Select[I any](source Stream[I], selector Selector[I]) Stream[I]
- type StreamFunc
Constants ¶
This section is empty.
Variables ¶
var ErrEnd = errors.New("end")
ErrEnd is the error returned by by the Next method of streams when there are no more items in the stream.
Functions ¶
Types ¶
type Sizer ¶
type Sizer interface { // Returns the number of items still available in the stream. Size(ctx context.Context) (size int, err error) }
Sizer is an interface that can optionally be implemented by streams that know what is their size. Some functions, for example the Slice function that builds an slice from a stream, can take advantage of this to allocate the required space in advance.
type Stream ¶
type Stream[I any] interface { // Next resturns the next item from the stream. Returns the EOS error if there are // no more items. Other errors may also be returned. For example, if the stream is backed // by a database table the database connection may fail and generate an error. Next(ctx context.Context) (item I, err error) }
Stream represents a stream of items.
func Delay ¶
Delay creates a new stream that returns the same items than the given source, but with an additional delay for each item. This is intended for tests and there is usually no reason to use in production code.
func Map ¶
Map creates a stream that contains the result of transforming the objects of the given stream with a mapper. Note that the actual calls to the mapper will not happen when this function is called, they will happen only when the stream is eventually consumed.