added generic types + FilterChanges

This commit is contained in:
2025-06-26 15:22:42 +02:00
parent 21430b0d65
commit 9990d7206d
7 changed files with 48 additions and 20 deletions

10
map.go
View File

@ -4,12 +4,12 @@ import "sync"
// MapPreserveOrder applies mapper to all I's coming from source 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 MapPreserveOrder[I, O any](source <-chan I, mapper func(I) O) (out <-chan O) {
func MapPreserveOrder[I, O any](source <-chan I, mapper Mapper[I, O]) (out <-chan O) {
return MapPreserveOrderWithRunner(source, getDefaultRunner(), mapper)
}
// MapPreserveOrderWithRunner behaves like MapPreserveOrder but uses runner to spawn its routines
func MapPreserveOrderWithRunner[I, O any](source <-chan I, runner Runner, mapper func(I) O) <-chan O {
func MapPreserveOrderWithRunner[I, O any](source <-chan I, runner Runner, mapper Mapper[I, O]) <-chan O {
out := make(chan O, cap(source))
outchannels := make(chan chan O, cap(source))
@ -43,12 +43,12 @@ func MapPreserveOrderWithRunner[I, O any](source <-chan I, runner Runner, mapper
// Map applies mapper to all I's coming from source and sends their return values to out.
// 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) <-chan O {
func Map[I, O any](source <-chan I, mapper Mapper[I, O]) <-chan O {
return MapWithRunner(source, getDefaultRunner(), mapper)
}
// 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 {
func MapWithRunner[I, O any](source <-chan I, runner Runner, mapper Mapper[I, O]) <-chan O {
out := make(chan O, cap(source))
go func() {
@ -72,7 +72,7 @@ func MapWithRunner[I, O any](source <-chan I, runner Runner, mapper func(I) O) <
// MapSuccessive applies mapper to all I's coming from source and sends their return values to out while preserving input order.
// All mappings will be done successively in a single thread
func MapSuccessive[I, O any](source <-chan I, mapper func(I) O) <-chan O {
func MapSuccessive[I, O any](source <-chan I, mapper Mapper[I, O]) <-chan O {
out := make(chan O, cap(source))
go func() {