Documentation
¶
Overview ¶
Package stream provides a variety of context-aware generic functions that operate on channels.
Index ¶
- func Filter[T any](ctx context.Context, in <-chan T, out chan<- T, ...) error
- func NopSink[T any](ctx context.Context, in <-chan T) error
- func NopSource[T any](_ context.Context, out chan<- T)
- func SliceSink[T any](ctx context.Context, in <-chan T) ([]T, error)
- func SliceSource[T any](ctx context.Context, in []T, out chan<- T) error
- func TextFileSource(ctx context.Context, path string, out chan<- string) error
- func Transform[S, T any](ctx context.Context, in <-chan S, out chan<- T, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Filter ¶
func Filter[T any](ctx context.Context, in <-chan T, out chan<- T, f func(context.Context, T) (bool, error)) error
Filter receives values from in, and passes them to f. If f reports true, the value is sent on out. After receiving all values from in, and in is closed, out is closed and Filter returns.
func NopSource ¶
NopSource closes the channel. The implementation is trivial, but is provided out of a sense of dedication to completeness.
func SliceSink ¶
SliceSink reads the values from the channel into a slice, until the channel is closed, then returns the slice.
func SliceSource ¶
SliceSource writes the values in the slice to the channel, one at a time, and closes the channel when done.
func TextFileSource ¶
TextFileSource reads lines from the file one at a time, and sends them into the channel. When reading is complete the channel is closed.
func Transform ¶
func Transform[S, T any](ctx context.Context, in <-chan S, out chan<- T, tf func(context.Context, S) (T, error)) error
Transform receives values from in, applies the transform tf, and sends the results on out. It does not receive a new value before sending the previous result. After transforming all values from in, and in is closed, out is closed and Transform returns.
Types ¶
This section is empty.