FlatMap function introduced

This commit is contained in:
milarin 2024-05-10 20:32:41 +02:00
parent 4612cb74b2
commit 78436e629c

15
flat.go
View File

@ -15,6 +15,21 @@ func FlatSlice[T any](source <-chan []T) <-chan T {
return out
}
func FlatMap[K comparable, V, T any](source <-chan map[K]V, unmapper func(key K, value V) T) <-chan T {
out := make(chan T, cap(source))
go func() {
defer close(out)
for slice := range source {
for k, v := range slice {
out <- unmapper(k, v)
}
}
}()
return out
}
func FlatChan[T any](source <-chan <-chan T) <-chan T {
out := make(chan T, cap(source))