Documentation ¶
Overview ¶
Package channels provides generic functions for channels.
Index ¶
- Variables
- func All[T any](c <-chan T, f func(el T) bool) bool
- func Any[T any](c <-chan T, f func(el T) bool) bool
- func ChunkEvery[T any](c <-chan T, count int) chan []T
- func Count[T comparable](c <-chan T, el T) int
- func Counter[T constraints.Integer](ctx context.Context, start T, step T) chan T
- func Drop[T any](c <-chan T, n int) chan T
- func Each[T any](c <-chan T, f func(el T))
- func Exponential[T constraints.Integer](ctx context.Context, start T, factor T) chan T
- func Filter[T any](c <-chan T, f func(el T) bool) chan T
- func Iterate[T constraints.Integer](ctx context.Context, val T, f func(val T) T) chan T
- func Map[T any, G any](c <-chan T, f func(el T) G) chan G
- func Max[T constraints.Ordered](c <-chan T) (T, error)
- func Min[T constraints.Ordered](c <-chan T) (T, error)
- func Range[T constraints.Integer](ctx context.Context, start T, end T, step T) chan T
- func Reduce[T any, G any](c <-chan T, acc G, f func(el T, acc G) G) G
- func Repeat[T constraints.Integer](ctx context.Context, val T) chan T
- func Replicate[T constraints.Integer](ctx context.Context, val T, n int) chan T
- func Scan[T any, G any](c <-chan T, acc G, f func(el T, acc G) G) chan G
- func Sum[T constraints.Ordered](c <-chan T) T
- func Take[T any](c <-chan T, count int) chan T
- func Tee[T any](c <-chan T, count int) []chan T
- func ToSlice[T any](c <-chan T) []T
Constants ¶
This section is empty.
Variables ¶
var ErrEmpty = errors.New("container is empty")
ErrEmpty is an error for empty slice when it's expected to have elements
Functions ¶
func ChunkEvery ¶
ChunkEvery returns channel with slices containing count elements each
func Count ¶
func Count[T comparable](c <-chan T, el T) int
Count return count of el occurrences in channel.
func Counter ¶
func Counter[T constraints.Integer](ctx context.Context, start T, step T) chan T
Counter is like Range, but infinite
func Drop ¶
Drop drops first n elements from channel c and returns a new channel with the rest. It returns channel do be unblocking. If you want array instead, wrap result into TakeAll.
func Each ¶
func Each[T any](c <-chan T, f func(el T))
Each calls f for every element in the channel
func Exponential ¶
func Exponential[T constraints.Integer](ctx context.Context, start T, factor T) chan T
Exponential generates elements from start with multiplication of value on factor on every step
func Filter ¶
Filter returns a new channel with elements from input channel for which f returns true
func Iterate ¶
func Iterate[T constraints.Integer](ctx context.Context, val T, f func(val T) T) chan T
Iterate returns an infinite list of repeated applications of f to val
func Max ¶
func Max[T constraints.Ordered](c <-chan T) (T, error)
Max returns the maximal element from channel
func Min ¶
func Min[T constraints.Ordered](c <-chan T) (T, error)
Min returns the minimal element from channel
func Range ¶
func Range[T constraints.Integer](ctx context.Context, start T, end T, step T) chan T
Range generates elements from start to end with given step
func Repeat ¶
func Repeat[T constraints.Integer](ctx context.Context, val T) chan T
Repeat returns channel that produces val infinite times
func Replicate ¶
func Replicate[T constraints.Integer](ctx context.Context, val T, n int) chan T
Replicate returns channel that produces val n times
func Sum ¶
func Sum[T constraints.Ordered](c <-chan T) T
Sum returns sum of all elements from channel
Types ¶
This section is empty.