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

View File

@ -4,13 +4,13 @@ import "sync"
// Each consumes all values and calls f for each of them.
// It blocks until source is closed
func Each[T any](source <-chan T, f func(T)) {
func Each[T any](source <-chan T, f Consumer[T]) {
EachWithRunner(source, getDefaultRunner(), f)
}
// Each consumes all values and calls f for each of them.
// It blocks until source is closed
func EachWithRunner[T any](source <-chan T, runner Runner, f func(T)) {
func EachWithRunner[T any](source <-chan T, runner Runner, f Consumer[T]) {
wg := &sync.WaitGroup{}
for value := range source {
@ -27,7 +27,7 @@ func EachWithRunner[T any](source <-chan T, runner Runner, f func(T)) {
// EachSuccessive consumes all values and calls f for each of them.
// It blocks until source is closed
func EachSuccessive[T any](source <-chan T, f func(T)) {
func EachSuccessive[T any](source <-chan T, f Consumer[T]) {
for value := range source {
f(value)
}