subway

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 3 Imported by: 0

README

subway

An experimental channel package using generics.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy[T any](ctx context.Context, input <-chan T, output ...chan<- T)

Copy reads from the input channel and sends messages to all of the output channels. The output channels are closed when the input channel is closed or when the context is cancelled.

func Equal

func Equal[T cmp.Ordered](ctx context.Context, c <-chan T, value T) <-chan T

func Filter

func Filter[T any](ctx context.Context, c <-chan T, f func(T) bool) <-chan T

func Greater

func Greater[T cmp.Ordered](ctx context.Context, c <-chan T, value T) <-chan T

func GreaterOrEqual

func GreaterOrEqual[T cmp.Ordered](ctx context.Context, c <-chan T, value T) <-chan T

func Less

func Less[T cmp.Ordered](ctx context.Context, c <-chan T, value T) <-chan T

func LessOrEqual

func LessOrEqual[T cmp.Ordered](ctx context.Context, c <-chan T, value T) <-chan T

func Make

func Make[T any](ctx context.Context, f func() (T, bool)) chan T

func Merge

func Merge[T any](ctx context.Context, input ...<-chan T) <-chan T

Merge returns all the messages from the given input channels on a single channel. The output channel is closed when all of the input channels are closed or when the context is cancelled.

func NotEqual

func NotEqual[T cmp.Ordered](ctx context.Context, c <-chan T, value T) <-chan T

func Pool

func Pool[T, R any](ctx context.Context, c <-chan T, size int, f Func[T, R]) <-chan Result[R]

Pool spawns size workers to processes messages on c using f, returning the results in a channel. The resulting channel must be read until it is closed or the process will hang.

func Split

func Split[T any](ctx context.Context, input <-chan T, output ...chan<- T)

Split reads from input and sends messages to any one of the output channels. The output channels are closed when the input channel is closed or when the context is cancelled.

func Tee

func Tee[T any](ctx context.Context, c chan T) (chan T, chan T)

func Worker

func Worker[T, R any](ctx context.Context, c <-chan T, f Func[T, R], res chan<- Result[R])

Worker reads c and calls f for each item until c is closed or the context is cancelled.

Types

type Func

type Func[T, R any] func(ctx context.Context, t T) (R, error)

Func is a function that performs an operation on t.

type Result

type Result[R any] struct {
	R   R
	Err error
}

Result holds the data returned by a Func.

Jump to

Keyboard shortcuts

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