chanz

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const (
	WriteSync = iota
	WriteAync
	WriteIfFree
)
View Source
const (
	ReadWait      = iota
	ReadIfWaiting = iota
)

Variables

This section is empty.

Functions

func Buffer

func Buffer[A any](size int, in <-chan A, options ...Option) ([]A, bool)

func Collect

func Collect[A any](c <-chan A, options ...Option) []A

Collect will collect all enteries in a channel into a slice and return it. It stops and returns when done or c is closed It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Compact

func Compact[A any](c <-chan A, equal func(a, b A) bool, options ...Option) <-chan A

Compact takes a chan and applies the "equal" func to every item and its predecessor. If it returns true, the current item being the same as the previous item, the current one will not be includes on the output chan The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func CompactWith

func CompactWith[A any](options ...Option) func(c <-chan A, equal func(a, b A) bool) <-chan A

CompactWith takes a chan and applies the "equal" func to every item and its predecessor. If it returns true, the current item being the same as the previous item, the current one will not be includes on the output chan The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Concat

func Concat[A any](cs ...<-chan A) <-chan A

Concat takes a slice of chans and put all items received on the returning chan

func ConcatWith

func ConcatWith[A any](options ...Option) func(cs ...<-chan A) <-chan A

ConcatWith takes a slice of chans and put all items received on the returning chan The input chans are read until closed in order. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Done

func Done[T any](c chan T) <-chan struct{}

Done takes a channel, c, that is ment to indicate that something is done and returns a chan struct{} that closes once c does It is ment to convert a channel of any type to a channel that aligns with context.Context.Done() if data is passed on c, Done will drain it

func Drop

func Drop[A any](c <-chan A, i int, options ...Option) <-chan A

Drop takes a chan and returns a chan. It will drop the first "i" items read from the in chan and write the remaining items onto the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func DropAll

func DropAll[A any](c <-chan A, async bool)

DropAll will consume a channel until it closes. If async is false, it will block until the channel is closed and all entries are consumed. If async is true it will immediately return and consume all elements in the background

func DropBuffer

func DropBuffer[A any](c <-chan A, async bool)

DropBuffer will drop everything in the channels buffer ()

func DropWhile

func DropWhile[A any](c <-chan A, drop func(a A) bool, options ...Option) <-chan A

DropWhile takes a chan and returns a chan. It will drop items until the drop function returns false, and will then write the remaining items onto the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func DropWhileWith

func DropWhileWith[A any](options ...Option) func(c <-chan A, drop func(a A) bool) <-chan A

DropWhileWith takes a chan and returns a chan. It will drop items until the drop function returns false, and will then write the remaining items onto the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func DropWith

func DropWith[A any](options ...Option) func(c <-chan A, i int) <-chan A

DropWith takes a chan and returns a chan. It will drop the first "i" items read from the in chan and write the remaining items onto the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func EveryDone

func EveryDone[T any](done ...<-chan T) <-chan T

EveryDone returns a channel that closes when all channels from the input arguments are closed

func FanIn

func FanIn[A any](cs ...<-chan A) <-chan A

FanIn will merge all input from input channels into one output channel. It differs from Flattenin that it reads from all channels concurrently instead of synchronized

func FanInWith

func FanInWith[A any](options ...Option) func(cs ...<-chan A) <-chan A

FanInWith will merge all input from input channels into one output channel. It differs from FlattenUntil in that it reads from all channels concurrently instead of synchronized The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func FanOut

func FanOut[A any](c <-chan A, size int, options ...Option) []<-chan A

FanOut will return a slice of chans on which entries read from the input chan are written to every output chan. A new entry won't be read from the input chan until all output chans has consumed entry, if the buffer is full. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func FanOutWith

func FanOutWith[A any](options ...Option) func(c <-chan A, size int) []<-chan A

FanOutWith will return a slice of chans on which entries read from the input chan are written to every output chan. A new entry won't be read from the input chan until all output chans has consumed entry, if the buffer is full. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Filter

func Filter[A any](c <-chan A, include func(a A) bool, options ...Option) <-chan A

Filter takes a chan and applies the "include" func to every item. If it returns true, the item is out on the output chan The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func FilterWith

func FilterWith[A any](options ...Option) func(c <-chan A, include func(a A) bool) <-chan A

FilterWith takes a chan and applies the "include" func to every item. If it returns true, the item is out on the output chan The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Flatten

func Flatten[A any](in <-chan []A, options ...Option) <-chan A

Flatten takes a chan of a slice put all items received on the returning chan, one by one The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func FlattenWith

func FlattenWith[A any](options ...Option) func(in <-chan []A) <-chan A

func Generate

func Generate[A any](elements ...A) <-chan A

Generate takes a slice of elements, returns a channel and writes the elements to the channel. It closes once all elements in the slice are written The return chan has a buffer of 0

func GenerateWith

func GenerateWith[A any](options ...Option) func(elements ...A) <-chan A

func Generator

func Generator[A any](gen func(func(A)), options ...Option) <-chan A

func GeneratorWith

func GeneratorWith[A any](options ...Option) func(gen func(func(A))) <-chan A

func Map

func Map[A any, B any](in <-chan A, mapper func(a A) B, options ...Option) <-chan B

Map will take a chan, in, and executes mapper and put the resulting on to the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func MapWith

func MapWith[A any, B any](options ...Option) func(in <-chan A, mapper func(a A) B) <-chan B

MapWith will take a chan, in, and executes mapper and put the resulting on to the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Partition

func Partition[A any](c <-chan A, predicate func(a A) bool, options ...Option) (satisfied, notSatisfied <-chan A)

Partition takes a chan and returns two chans. For every item consumed it is passed through the predicate func. If it returns true, the item is put on the satisfied chan otherwise it is put on the notSatisfied chan The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func PartitionWith

func PartitionWith[A any](options ...Option) func(c <-chan A, predicate func(a A) bool) (satisfied, notSatisfied <-chan A)

PartitionWith takes a chan and returns two chans. For every item consumed it is passed through the predicate func. If it returns true, the item is put on the satisfied chan otherwise it is put on the notSatisfied chan The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Peek

func Peek[A any](in <-chan A, apply func(a A), options ...Option) <-chan A

Peek will take a chan, in, and executes apply on every element and then writes the element to the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func PeekWith

func PeekWith[A any](options ...Option) func(in <-chan A, apply func(a A)) <-chan A

PeekWith will take a chan, in, and executes apply on every element and then writes the element to the return chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func ReadFrom

func ReadFrom[A any](c chan A, mode int) func() (m A, ok bool)

func Readers

func Readers[A any](chans ...chan A) []<-chan A

Readers takes a slice of chans and returns the reader version of it

func SomeDone

func SomeDone[T any](done ...<-chan T) <-chan T

SomeDone returns a channel that closes as soon as any channels from the input arguments are closed

func Take

func Take[A any](c <-chan A, i int, options ...Option) <-chan A

Take takes a chan and returns a chan. It will write the first "i" items read from the in chan onto the return chan and then close the read chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func TakeBuffer

func TakeBuffer[A any](c <-chan A) []A

TakeBuffer will take everything in the channels buffer ()

func TakeWhile

func TakeWhile[A any](c <-chan A, take func(a A) bool, options ...Option) <-chan A

TakeWhile takes a chan and returns a chan. It will write all items read from the in chan onto the return chan until the take function returns false, then the out chan will close The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func TakeWhileWith

func TakeWhileWith[A any](options ...Option) func(c <-chan A, take func(a A) bool) <-chan A

TakeWhileWith takes a chan and returns a chan. It will write all items read from the in chan onto the return chan until the take function returns false, then the out chan will close The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func TakeWith

func TakeWith[A any](option ...Option) func(c <-chan A, i int) <-chan A

TakeWith takes a chan and returns a chan. It will write the first "i" items read from the in chan onto the return chan and then close the read chan. The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

func Unzip

func Unzip[A any, B any, C any](zipped <-chan C, unzipper func(c C) (A, B), options ...Option) (<-chan A, <-chan B)

Unzip takes one chan and returns a chan. It will read a C item from the input chan, apply the unzipper to the two resulting items on the output chans The return chan has a buffer of buffer size supplied in input args. It will stop once the any in chan are closed, done is closed

func WriteTo

func WriteTo[A any](c chan<- A, mode int) func(m A)

func Writers

func Writers[A any](chans ...chan A) []chan<- A

Writers takes a slice of chans and returns the writer version of it

func Zip

func Zip[A any, B any, C any](ac <-chan A, bc <-chan B, zipper func(a A, b B) C, options ...Option) <-chan C

Zip takes two chans and returns a chan. it will read a A item and a B item. Apply the zipper to these and output the result on the returning chan The return chan has a buffer of buffer size supplied in input Option, default is 0. It will stop once "in", "done" channel is closed or the context.Done is closed, which is supplied in Option

Types

type Option

type Option func(s settings) settings

func OpBuffer

func OpBuffer(size int) Option

func OpContext

func OpContext(ctx context.Context) Option

func OpDone

func OpDone(done <-chan struct{}) Option

Jump to

Keyboard shortcuts

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