diff --git a/map.go b/map.go index 5b40f16..42c4e6d 100644 --- a/map.go +++ b/map.go @@ -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() {