stream

package
v0.0.0-...-9687f63 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package stream provides a variety of context-aware generic functions that operate on channels.

Index

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 NopSink

func NopSink[T any](ctx context.Context, in <-chan T) error

NopSink reads and discards all the values from the channel.

func NopSource

func NopSource[T any](_ context.Context, out chan<- T)

NopSource closes the channel. The implementation is trivial, but is provided out of a sense of dedication to completeness.

func SliceSink

func SliceSink[T any](ctx context.Context, in <-chan T) ([]T, error)

SliceSink reads the values from the channel into a slice, until the channel is closed, then returns the slice.

func SliceSource

func SliceSource[T any](ctx context.Context, in []T, out chan<- T) error

SliceSource writes the values in the slice to the channel, one at a time, and closes the channel when done.

func TextFileSource

func TextFileSource(ctx context.Context, path string, out chan<- string) error

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.

Jump to

Keyboard shortcuts

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