Documentation
¶
Index ¶
- func Async[T1 any](f func() T1) chan T1
- func AsyncIn[T1 any](in T1) (out chan T1)
- func AsyncOut[T1, T2 any](in chan T1, f func(T1) T2, out chan T2)
- func AsyncPipe[T1, T2 any](in chan T1, f func(T1) T2) chan T2
- func AsyncV[T1 any](funcList ...func() T1) chan T1
- func AsyncVUnpanic[T1 any](funcList ...func() T1) chan T1
- func Avg[T Number](n ...T) (avg T)
- func AvgF64[T Number](n ...T) (avg float64)
- func AvgF64F64[T Number](n ...T) (avg float64)
- func ChanGen[T any](genFunc func() T, ch chan T)
- func ChanGenCloser[T any](genFunc func() T, ch chan T) (closer func(closeChannel ...bool))
- func ChanGenN[T any](count int, genFunc func(idx int) T, out chan T, closeOutputChan ...bool) (finished chan bool)
- func ChanToSlice[T any](inCh chan T) []T
- func ChanToSliceN[T any](inCh chan T, n int) []T
- func ChanToSliceNTimeout[T any](inCh chan T, n int, timeout time.Duration) []T
- func CompareSliceSet[T comparable](v1 []T, v2 []T) bool
- func FilterChan[T any](filterFunc func(T) bool, in chan T) (out chan T)
- func FilterChanErr[T any](filterFunc func(T) (bool, error), in chan T) (out chan T, errCh chan error)
- func FilterMap[K comparable, V any](filterFunc func(k K, v V) (accept bool), in map[K]V) (out map[K]V)
- func FilterSlice[V any](filterFunc func(idx int, v V) (accept bool), in []V) (out []V)
- func FirstOrDefault[T any](slice []T, def T) (out T)
- func FirstOrEmpty[T any](slice []T) (out T)
- func GenChan[T any](genFunc func() T) chan T
- func GenChanCloser[T any](genFunc func() T) (out chan T, closer func(closeChannel ...bool))
- func GenChanN[T any](genFunc func(idx int) T, count int, closeOutputChan ...bool) (ch chan T)
- func GenMap[K comparable, V any](count int, f func(idx int) (K, V)) (out map[K]V)
- func GenSlice[T any](count int, f func(idx int) T) (out []T)
- func GenSliceToChan[T any](in []T, closeOutputChan ...bool) (out chan T)
- func IgnoreErr[T any](in T, err error) (out T)
- func LastOrDefault[T any](slice []T, def T) (out T)
- func LastOrEmpty[T any](slice []T) (out T)
- func Map[T1, T2 any](mapFunc func(v T1) T2, slice ...T1) []T2
- func MapErr[T1, T2 any](mapFunc func(v T1) (T2, error), slice ...T1) (out []T2, err error)
- func MapMap[K1, K2 comparable, V1, V2 any](mapFunc func(k K1, v V1) (K2, V2), in map[K1]V1) (out map[K2]V2)
- func MapMapInplace[K1, K2 comparable, V1, V2 any](mapFunc func(k K1, v V1) (K2, V2), in map[K1]V1, out map[K2]V2)
- func MapSlice[T1, T2 any](mapFunc func(v T1) T2, slice []T1) []T2
- func MapSliceErr[T1, T2 any](mapFunc func(v T1) (T2, error), slice []T1) (out []T2, err error)
- func MapSliceErrSkip[T1, T2 any](mapFunc func(v T1) (T2, error), slice []T1) (out []T2, err error)
- func MapSliceKey[K comparable, V any](in map[K]V) (out []K)
- func MapSliceSkip[T1, T2 any](mapFunc func(v T1) (T2, bool), slice []T1) (out []T2)
- func MapSliceValue[K comparable, V any](in map[K]V) (out []V)
- func MapToSlice[K1 comparable, V any, V2 any](f func(k K1, v V) V2, in map[K1]V) (out []V2)
- func MapToSliceSorted[K1 comparable, V any, V2 any](f func(k K1, v V) V2, sortFuncLess func(left K1, right K1) bool, in map[K1]V) (out []V2)
- func Max[T Number](n ...T) (max T)
- func Median[T Number](n ...T) (median T)
- func MedianF64[T Number](n ...T) (median float64)
- func Min[T Number](n ...T) (min T)
- func Must[T any](in T, err error) (out T)
- func ParallelMap[T1, T2 any](mapFunc func(T1) T2, concurrency int, slice ...T1) []T2
- func ParallelMapMap[K1, K2 comparable, V1, V2 any](mapFunc func(k K1, v V1) (K2, V2), concurrency int, in map[K1]V1) map[K2]V2
- func ParallelMapSlice[T1, T2 any](mapFunc func(T1) T2, concurrency int, slice []T1) []T2
- func ParallelMapSliceChan[T1, T2 any](mapFunc func(T1) T2, concurrency int, slice []T1) chan T2
- func ParallelMapSliceChanFinisher[T1, T2 any](mapFunc func(T1) T2, concurrency int, slice []T1) (chan T2, chan bool)
- func Retry[T any](n int, f func() (T, error)) (T, error)
- func RetryAfter[T any](min_interval, max_interval, total_timeout time.Duration, f func() (T, error)) (T, error)
- func SliceDedupe[T comparable](slice []T) (out []T)
- func SliceDedupeFunc[T any, C comparable](slice []T, convert func(T) C) (out []T)
- func SliceDiff[T comparable](v1 []T, v2 []T) (inLeft []T, inRight []T)
- func SliceDiffFunc[T1 any, T2 any, Z comparable](v1 []T1, v2 []T2, convertV1 func(T1) Z, convertV2 func(T2) Z) (inLeft []T1, inRight []T2)
- func SliceIn[T comparable](slice []T, contains T) bool
- func SliceMap[T any, M comparable](f func(T) M, a []T) map[M]T
- func SliceMapFunc[T any, K comparable, V any](mapFunc func(T) (K, V), slice []T) map[K]V
- func SliceMapSet[T comparable](a []T) (n map[T]bool)
- func SliceMapSetFunc[T any, M comparable](mapFunc func(T) M, slice []T) (n map[M]bool)
- func SliceMapSkip[T any, Z comparable](comparable func(T) (comparable Z, skip bool), slice []T) (m map[Z]T)
- func SliceReverse[T any](in []T) (out []T)
- func SliceReverseInplace[T any](out []T)
- func SliceToChan[T any](in []T, out chan T, closeOutputChan ...bool)
- func Sum[T Number](n ...T) (sum T)
- func SumF64[T Number](n ...T) (sum float64)
- func Try[T any](f ...func() (T, error)) (out T, err error)
- func WorkerPool[T1, T2 any](input chan T1, output chan T2, worker func(T1) T2, concurrency int, ...)
- func WorkerPoolAsync[T1, T2 any](worker func(T1) T2, concurrency int) (async func(T1) chan T2, stop func())
- func WorkerPoolBackground[T1, T2 any](input chan T1, worker func(T1) T2, concurrency int, closeOutputChan ...bool) (output chan T2)
- func WorkerPoolDrain[T1 any](worker func(T1), concurrency int, input chan T1) (finish chan bool)
- func WorkerPoolFinisher[T1, T2 any](input chan T1, output chan T2, worker func(T1) T2, concurrency int) chan bool
- type ErrSkip
- type KeyValue
- type Number
- type Response
- type ValueIndex
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Async ¶ added in v0.1.7
func Async[T1 any](f func() T1) chan T1
Async runs a function in goroutine and returns pipe with result
Example ¶
// make our conversion output channel out := make(chan string, 1) // queue first element AsyncOut( AsyncPipe( AsyncIn(time.Unix(123456789, 0)), func(in time.Time) (out string) { return in.Format("2006-01-02") }, ), func(in string) (out string) { // just to make sure that one comes second time.Sleep(time.Millisecond * 10) return "date: " + in }, out) // queue second element AsyncOut( AsyncPipe( AsyncPipe( AsyncIn(12345678), func(in int) (out time.Time) { return time.Unix(int64(in), 0) }, ), func(t time.Time) string { return t.Format("2006-01-02") }, ), func(in string) (out string) { return "date: " + in }, out) fmt.Printf("%s %s", <-out, <-out, )
Output: date: 1970-05-23 date: 1973-11-29
func AsyncIn ¶ added in v0.1.7
func AsyncIn[T1 any](in T1) (out chan T1)
AsyncIn turns value into channel with value
func AsyncOut ¶ added in v0.1.7
func AsyncOut[T1, T2 any](in chan T1, f func(T1) T2, out chan T2)
AsyncOut takes value and feeds it to function returning asynchronously to channel
func AsyncPipe ¶ added in v0.1.7
func AsyncPipe[T1, T2 any](in chan T1, f func(T1) T2) chan T2
AsyncPipe runs a function in goroutine from input channel and returns pipe with result
func AsyncV ¶ added in v0.1.8
func AsyncV[T1 any](funcList ...func() T1) chan T1
AsyncV runs a number of functions in goroutine and returns pipe with result then closes after goroutines finish order is not guaranteed
func AsyncVUnpanic ¶ added in v0.1.8
func AsyncVUnpanic[T1 any](funcList ...func() T1) chan T1
AsyncVUnpanic runs a number of functions in goroutine and returns pipe with result then closes after goroutines finish order is not guaranteed panics are suppressed
func AvgF64 ¶ added in v0.1.4
AvgF64 calculates average with final division using float64 type int overflow can still happen
func AvgF64F64 ¶ added in v0.1.4
AvgF64F64 calculates average after converting any input to float64 to avoid integer overflows
func ChanGen ¶ added in v0.1.4
func ChanGen[T any](genFunc func() T, ch chan T)
ChanGen sends function output to provided channel
func ChanGenCloser ¶ added in v0.1.4
ChanGenCloser generates a channel that is fed from function results. Running closer func will stop it. Closing is asynchronous and number of events in flight depends on channel size so don't rely on stooping after exact number of calls, If you need synchronous close here you're probably doing something wrong
func ChanGenN ¶ added in v0.1.8
func ChanGenN[T any](count int, genFunc func(idx int) T, out chan T, closeOutputChan ...bool) (finished chan bool)
ChanGenN runs function n times and sends the result to the provided channel resulting channel will be sent `true` when the function finishes last send Function gets id of element starting from 0. setting optional argument to true will close the channel after finishing
func ChanToSlice ¶ added in v0.1.4
func ChanToSlice[T any](inCh chan T) []T
ChanToSlice loads channel messages to slice until channel is closed
func ChanToSliceN ¶ added in v0.1.4
ChanToSliceN loads up to n elements from to slice to channel
func ChanToSliceNTimeout ¶ added in v0.1.8
ChanToSliceNTimeout loads up to n elements from to slice to channel or up until timeout expires
func CompareSliceSet ¶
func CompareSliceSet[T comparable](v1 []T, v2 []T) bool
CompareSliceSet compares 2 slices and returns true if all elements of slice v1 are the same as in v2 order does not matter, the duplicates are ignored
func FilterChan ¶ added in v0.1.3
FilterChan filters elements going thru a channel close is propagated
func FilterChanErr ¶ added in v0.1.4
func FilterChanErr[T any](filterFunc func(T) (bool, error), in chan T) (out chan T, errCh chan error)
FilterChanErr filters elements going thru channel, redirecting errors to separate channel both channels need to be read or else it will stall close is propagated
func FilterMap ¶ added in v0.1.2
func FilterMap[K comparable, V any](filterFunc func(k K, v V) (accept bool), in map[K]V) (out map[K]V)
FilterMap runs function on every element of map and adds it to result map if it returned true
func FilterSlice ¶ added in v0.1.2
FilterSlice runs function on every element of slice and adds it to result slice if it returned true
func FirstOrDefault ¶ added in v0.1.8
func FirstOrDefault[T any](slice []T, def T) (out T)
FirstOrDefault returns first element of slice or passed default value
func FirstOrEmpty ¶ added in v0.1.8
func FirstOrEmpty[T any](slice []T) (out T)
FirstOrEmpty returns first element of slice or empty/default type
func GenChan ¶ added in v0.1.8
func GenChan[T any](genFunc func() T) chan T
GenChan generates a channel that is fed from function results
func GenChanCloser ¶ added in v0.1.8
func GenChanN ¶ added in v0.1.8
GenChanN generates channel that will run function n times and send result to channel, then close it Function gets id of element starting from 0. setting optional argument to true will close the channel after finishing
func GenMap ¶ added in v0.1.8
func GenMap[K comparable, V any](count int, f func(idx int) (K, V)) (out map[K]V)
GenMap generates a map of given size based on passed function. Function gets id of element starting from 0.
func GenSlice ¶ added in v0.1.8
GenSlice generates a slice of given length based on passed function. Function gets id of element starting from 0.
func GenSliceToChan ¶ added in v0.1.8
GenSliceToChan returns channel with background goroutine feeding it data from slice
Example ¶
// jobs to do input := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} output := ChanToSlice( // make slice out of channel WorkerPoolBackground( // that we got out of worker GenSliceToChan(input, true), // that got fed input from slice via channel func(v int) float64 { // pretend we have some work time.Sleep(time.Millisecond*20 + time.Duration(rand.Int31n(20))) return float64(v) * 1.5 }, 16, true, // in parallel )) fmt.Printf("%+v->(1.5x)->%+v", Sum(input...), Sum(output...))
Output: 55->(1.5x)->82.5
func IgnoreErr ¶ added in v1.1.0
IgnoreErr takes any value, and on error returns the default value You should probably not use it...
func LastOrDefault ¶ added in v0.1.8
func LastOrDefault[T any](slice []T, def T) (out T)
LastOrDefault returns last element of slice or passed default value
func LastOrEmpty ¶ added in v0.1.8
func LastOrEmpty[T any](slice []T) (out T)
LastOrEmpty returns last element of slice or empty/default type
func Map ¶
func Map[T1, T2 any](mapFunc func(v T1) T2, slice ...T1) []T2
Map maps the list of variadic(...) values via function. It is provided as convenience, MapSlice() should be used when you have incoming slice
func MapErr ¶
MapErr maps the list of variadic(...) values via function. and returns on first error Returns slice with elements that didn't return error before the failure so index of the first element in error is essentially `slice[len(out)]`
func MapMap ¶ added in v0.1.9
func MapMap[K1, K2 comparable, V1, V2 any](mapFunc func(k K1, v V1) (K2, V2), in map[K1]V1) (out map[K2]V2)
MapMap runs every map element thru function that returns new key and value, and returns that in another map. Types can vary between in and out.
func MapMapInplace ¶ added in v0.1.9
func MapMapInplace[K1, K2 comparable, V1, V2 any](mapFunc func(k K1, v V1) (K2, V2), in map[K1]V1, out map[K2]V2)
MapMapInplace runs every map element thru function that returns new key and value, and puts it into existing map. Types can vary between in and out.
func MapSlice ¶
func MapSlice[T1, T2 any](mapFunc func(v T1) T2, slice []T1) []T2
MapSlice maps slice using provided function
Example ¶
out := MapSlice( func(i int) string { return fmt.Sprintf("-=0x%02x=-", i) }, MapSlice( func(i int) int { return i + 1 }, MapSlice( func(i int) int { return i * i }, GenSlice(10, func(idx int) int { return idx }), ), ), ) fmt.Printf("%+v", out)
Output: [-=0x01=- -=0x02=- -=0x05=- -=0x0a=- -=0x11=- -=0x1a=- -=0x25=- -=0x32=- -=0x41=- -=0x52=-]
func MapSliceErr ¶
MapSliceErr maps slice using provided function, returning first error Returns slice with elements that didn't return error
func MapSliceErrSkip ¶ added in v0.1.3
MapSliceErrSkip maps slice using provided function, allowing to skip entries by returning ErrSkip Returns on first non `ErrSkip` error
func MapSliceKey ¶
func MapSliceKey[K comparable, V any](in map[K]V) (out []K)
MapSliceKey returns keys of a map in slice
func MapSliceSkip ¶ added in v0.1.3
MapSliceSkip maps slice using provided function, allowing to skip entries by returning true Returns slice with elements that didn't return true
func MapSliceValue ¶
func MapSliceValue[K comparable, V any](in map[K]V) (out []V)
MapSliceValue returns values of a map in slice
func MapToSlice ¶ added in v0.1.4
func MapToSlice[K1 comparable, V any, V2 any](f func(k K1, v V) V2, in map[K1]V) (out []V2)
MapToSlice converts map into slice via specified function
func MapToSliceSorted ¶ added in v1.3.0
func MapToSliceSorted[K1 comparable, V any, V2 any]( f func(k K1, v V) V2, sortFuncLess func(left K1, right K1) bool, in map[K1]V, ) (out []V2)
MapToSliceSorted converts map into slice via specified function
func Max ¶ added in v0.1.4
func Max[T Number](n ...T) (max T)
Max returns biggest number will panic on empty
func Min ¶ added in v0.1.4
func Min[T Number](n ...T) (min T)
Min returns smallest number will panic on empty
func Must ¶ added in v1.1.0
Must takes any value and error, returns the value and panics if error happens.
func ParallelMap ¶ added in v0.1.1
ParallelMapSlice takes variadic argument and runs all of them thru function in parallel, up to `concurrency` goroutines Order of elements in slice is kept
func ParallelMapMap ¶ added in v0.1.10
func ParallelMapMap[K1, K2 comparable, V1, V2 any]( mapFunc func(k K1, v V1) (K2, V2), concurrency int, in map[K1]V1, ) map[K2]V2
ParallelMapMap takes map and runs each element thru function in parallel, storing result in a map
func ParallelMapSlice ¶ added in v0.1.1
ParallelMapSlice takes slice and runs it thru function in parallel, up to `concurrency` goroutines Order of elements in slice is kept
Example ¶
data := []string{"1", "3", "2", "7", "9", "12"} mappedData := ParallelMapSlice( // function used to map func(v string) int { time.Sleep(time.Millisecond * time.Duration(rand.Int31n(10))) i, _ := strconv.Atoi(v) return i }, 3, // run it at least this many times data) // order stays fmt.Printf("%T%+v\n%T%+v", data, data, mappedData, mappedData)
Output: []string[1 3 2 7 9 12] []int[1 3 2 7 9 12]
func ParallelMapSliceChan ¶ added in v0.1.4
ParallelMapSliceChan feeds slice to function in parallel and returns channels with function output channel is closed when function finishes. Caller should close input channel when it finishes sending or else it will leak goroutines
func ParallelMapSliceChanFinisher ¶ added in v0.1.4
func ParallelMapSliceChanFinisher[T1, T2 any](mapFunc func(T1) T2, concurrency int, slice []T1) (chan T2, chan bool)
ParallelMapSliceChanFinisher feeds slice to function in parallel and returns channels with function output channel is closed when function finishes. Caller should close input channel when it finishes sending or else it will leak goroutines Second channel will return true (and then be closed) when the worker finishes parsing
func RetryAfter ¶ added in v0.1.8
func RetryAfter[T any]( min_interval, max_interval, total_timeout time.Duration, f func() (T, error), ) (T, error)
RetryAfter retries function till it returns without error, first after min_interval, then with increasing intervals up to max_interval with last retry happening near total_timeout Intended use is to be able to say "retry for 10 minutes, at the very least every minute, but not shorter than 10 seconds to account for TCP retransmissions"
func SliceDedupe ¶ added in v0.1.8
func SliceDedupe[T comparable](slice []T) (out []T)
SliceDedupe removes duplicates
func SliceDedupeFunc ¶ added in v0.1.8
func SliceDedupeFunc[T any, C comparable](slice []T, convert func(T) C) (out []T)
SliceDedupeFunc removes duplicates with function to convert the value to comparable
func SliceDiff ¶
func SliceDiff[T comparable](v1 []T, v2 []T) (inLeft []T, inRight []T)
SliceDiff compares two slices of comparable values and returns slice of elements that are only in first/left element and ones that are only in right element Duplicates are ignored. `([]T, []T) -> (leftOnly []T, rightOnly []T)`
func SliceDiffFunc ¶
func SliceDiffFunc[T1 any, T2 any, Z comparable]( v1 []T1, v2 []T2, convertV1 func(T1) Z, convertV2 func(T2) Z, ) (inLeft []T1, inRight []T2)
SliceDiffFunc compares two slices of any value using one conversion function per type to convert it into conmparables returns slice of elements that are only in first/left element and ones that are only in right element. Duplicates are ignored. ([]DataT,[]ReturnT) -> (leftOnly []DataT, rightOnly []ReturnT)
Example ¶
data1 := []string{"1", "2", "3", "4", "5"} data2 := []float32{1, 7, 3, 4} stringToInt := func(s string) int { i, _ := strconv.Atoi(s) return i } floatToInt := func(f float32) int { return int(f) } left, right := SliceDiffFunc(data1, data2, stringToInt, floatToInt) fmt.Printf("left: %T%+v right: %T%+v", left, left, right, right)
Output: left: []string[2 5] right: []float32[7]
func SliceIn ¶ added in v0.1.5
func SliceIn[T comparable](slice []T, contains T) bool
SliceIn checks if slice contains a value. Value must be comparable
func SliceMap ¶
func SliceMap[T any, M comparable](f func(T) M, a []T) map[M]T
SliceMap turn slice into a map via extracting key from it using helper function and setting the map value to that slice `[]Struct{} -> map[func(Struct)]Struct`
func SliceMapFunc ¶ added in v1.2.0
func SliceMapFunc[T any, K comparable, V any](mapFunc func(T) (K, V), slice []T) map[K]V
SliceMapFunc extracts key and value for map from slice using function `[]Any -> map[comparable K]V`
func SliceMapSet ¶
func SliceMapSet[T comparable](a []T) (n map[T]bool)
SliceMapSet turns slice into map with key being slice elements and value being true boolean `[]Comparable -> map[Comparable]bool{true}`
func SliceMapSetFunc ¶ added in v0.0.3
func SliceMapSetFunc[T any, M comparable](mapFunc func(T) M, slice []T) (n map[M]bool)
SliceMapSetFunc turns slice into map with key being slice elements passed thru specified function and value being true boolean `[]Any -> map[func(Any)Comparable]bool{true}`
func SliceMapSkip ¶
func SliceMapSkip[T any, Z comparable](comparable func(T) (comparable Z, skip bool), slice []T) (m map[Z]T)
SliceMapSkip works like `SliceMap` but allows slice->map function to skip elements via returning true to second argument `[]Struct{} -> map[func(Struct)]Struct`
Example ¶
type CS struct { Name string Value string } data := []CS{{Name: "t1", Value: "v1"}, {Name: "t2", Value: "v2"}, {Name: "t3", Value: "v3"}, {Name: "t4", Value: "v4"}} sliceMap := SliceMapSkip(func(t CS) (string, bool) { if t.Name == "t2" { return t.Name, true } else { return t.Name, false } }, data) fmt.Printf("map from slice with skipped t2: [%+v]", sliceMap)
Output: map from slice with skipped t2: [map[t1:{Name:t1 Value:v1} t3:{Name:t3 Value:v3} t4:{Name:t4 Value:v4}]]
func SliceReverse ¶ added in v1.2.0
func SliceReverse[T any](in []T) (out []T)
func SliceReverseInplace ¶ added in v1.2.0
func SliceReverseInplace[T any](out []T)
func SliceToChan ¶ added in v0.1.4
SliceToChan feeds slice to channel
func WorkerPool ¶ added in v0.1.1
func WorkerPool[T1, T2 any](input chan T1, output chan T2, worker func(T1) T2, concurrency int, closeOutputChan ...bool)
WorkerPool spawns `concurrency` goroutines eating from input channel and sending it to output channel caller should take care of closing input channel after it finished sending requests output channel will be closed after input is processed and closed optionally setting last option to true will make it close output channel
func WorkerPoolAsync ¶ added in v0.1.7
func WorkerPoolAsync[T1, T2 any](worker func(T1) T2, concurrency int) (async func(T1) chan T2, stop func())
WorkerPoolAsync returns a function that adds new job to queue and returns a channel with result, and function to stop worker
Example ¶
// make our worker with function to mangle data async, finish := WorkerPoolAsync( func(i int) string { return strconv.Itoa(i) }, 2) defer finish() // close the pool once we stop using it // queue some jobs job1 := async(1) job2 := async(2) job3 := async(3) job4 := async(4) // all of those jobs are running in background at this point // now get results fmt.Printf("%s %s %s %s", <-job1, <-job3, <-job2, <-job4, )
Output: 1 3 2 4
func WorkerPoolBackground ¶ added in v0.1.4
func WorkerPoolBackground[T1, T2 any](input chan T1, worker func(T1) T2, concurrency int, closeOutputChan ...bool) (output chan T2)
WorkerPoolBackground spawns `concurrency` goroutines eating from input channel and returns output channel with results optionally setting last option to true will make it close output channel
Example ¶
out := WorkerPoolBackground( WorkerPoolBackground( WorkerPoolBackground( GenChanN(func(idx int) int { return idx + 1 }, 3, true), func(i int) string { return strconv.Itoa(i) }, 4, true), func(s string) string { return ">" + s }, 5, true, ), func(s string) string { return " |" + s }, 6, true) sliceOut := ChanToSlice(out) sort.Slice(sliceOut, func(i, j int) bool { return sliceOut[i] < sliceOut[j] }) fmt.Printf("%v", sliceOut)
Output: [ |>1 |>2 |>3]
func WorkerPoolDrain ¶ added in v0.1.7
WorkerPoolDrain runs function per input without returning anything. Goroutines close on channel close. returns finish channel that returns single boolean true after goroutines finish
func WorkerPoolFinisher ¶ added in v0.1.1
func WorkerPoolFinisher[T1, T2 any](input chan T1, output chan T2, worker func(T1) T2, concurrency int) chan bool
WorkerPoolFinisher runs WorkerPool in the background and returns channel that returns `true` then closes when workers finish
Types ¶
type KeyValue ¶ added in v0.1.10
type KeyValue[Key comparable, Value any] struct { K Key V Value }
KeyValue represents map element
type Response ¶ added in v0.1.7
type Response[DataT, ReturnT any] struct { ReturnCh chan ReturnT Data DataT }
Response is used to pass data and channel to return value to worker
type ValueIndex ¶ added in v0.1.7
ValueIndex contains value with source index for ordered operation