renamed MapParallel to Map, renamed Map to MapSuccessive

This commit is contained in:
Timon Ringwald 2022-08-02 17:31:02 +02:00
parent 110846d866
commit 7e7234cf8f

18
map.go
View File

@ -1,13 +1,15 @@
package channel
// MapParallel applies mapper to all I's coming from in and sends their return values to out while preserving input order.
// All mappings will be done as concurrently as possible
func MapParallel[I, O any](source <-chan I, mapper func(I) O) (out <-chan O) {
return MapParallelWithRunner(source, NewUnlimitedRunner(), mapper)
import "runtime"
// Map applies mapper to all I's coming from in and sends their return values to out while preserving input order.
// All mappings will be done as concurrently as possible using as many threads as there are CPU cores
func Map[I, O any](source <-chan I, mapper func(I) O) (out <-chan O) {
return MapWithRunner(source, NewLimitedRunner(runtime.NumCPU()), mapper)
}
// MapParallelWithRunner behaves like MapParallel but uses runner to spawn its routines
func MapParallelWithRunner[I, O any](source <-chan I, runner Runner, mapper func(I) O) <-chan O {
// MapWithRunner behaves like Map but uses runner to spawn its routines
func MapWithRunner[I, O any](source <-chan I, runner Runner, mapper func(I) O) <-chan O {
out := make(chan O, cap(source))
outchannels := make(chan chan O, cap(source))
@ -39,9 +41,9 @@ func MapParallelWithRunner[I, O any](source <-chan I, runner Runner, mapper func
return out
}
// Map applies mapper to all I's coming from in and sends their return values to out while preserving input order.
// MapSuccessive applies mapper to all I's coming from in and sends their return values to out while preserving input order.
// All mappings will be done successively
func Map[I, O any](source <-chan I, mapper func(I) O) <-chan O {
func MapSuccessive[I, O any](source <-chan I, mapper func(I) O) <-chan O {
out := make(chan O, cap(source))
go func() {