Documentation ¶
Index ¶
- func Reduce[I, O any](input Pipeline[I], reducer func(context.Context, I, O) (O, error), ...) (O, error)
- func Sink[T any](input Pipeline[T], sink func(context.Context, T) error) error
- type Pipeline
- func Filter[T any](input Pipeline[T], filter func(context.Context, T) (bool, error)) Pipeline[T]
- func Flatten[T any](input Pipeline[[]T]) Pipeline[T]
- func Map[I, O any](input Pipeline[I], mapper func(context.Context, I) (O, error)) Pipeline[O]
- func ParallelFilter[T any](input Pipeline[T], filter func(context.Context, T) (bool, error)) Pipeline[T]
- func ParallelMap[I, O any](input Pipeline[I], mapper func(context.Context, I) (O, error)) Pipeline[O]
- func SliceSource[T any](ctx context.Context, slice []T) Pipeline[T]
- func Source[T any](ctx context.Context, source func(context.Context, func(T) error) error) Pipeline[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Reduce ¶
func Reduce[I, O any](input Pipeline[I], reducer func(context.Context, I, O) (O, error), initialState O) (O, error)
Reduce is a terminal processing stage that consumes values of type I and reduces them down to a single value of type O using the given reducer function, beginning with the given initial state.
Types ¶
type Pipeline ¶
type Pipeline[T any] struct { // contains filtered or unexported fields }
Pipeline is a connection between two processing stages working on type T.
func Filter ¶
Filter is a processing stage that passes or blocks values of type T according to whether the given filter function returns true or false, respectively.
func Flatten ¶
Flatten is a processing stage that collapses a sequence of slices of type T into a single slice of the same type.
func Map ¶
Map is a processing stage that converts values of type I into values of type O using the given mapper function.
func ParallelFilter ¶
func ParallelFilter[T any](input Pipeline[T], filter func(context.Context, T) (bool, error)) Pipeline[T]
ParallelFilter is identical to Filter except the filtering operations are performed in parallel. This process is not guaranteed to maintain the order of the values.
func ParallelMap ¶
func ParallelMap[I, O any](input Pipeline[I], mapper func(context.Context, I) (O, error)) Pipeline[O]
ParallelMap is identical to Map except the mapping operations are performed in parallel. This process is not guaranteed to maintain the order of the values.
func SliceSource ¶
SliceSource is a helper function around Source that generates values from the given slice.
func Source ¶
func Source[T any](ctx context.Context, source func(context.Context, func(T) error) error) Pipeline[T]
Source is a processing stage that generates values of type T using the given source function. This and all subsequent stages will run within an errgroup created from the given Context.
The channel passed to the generator function is automatically closed when the function returns.