diff --git a/flat.go b/flat.go new file mode 100644 index 0000000..a070da9 --- /dev/null +++ b/flat.go @@ -0,0 +1,31 @@ +package channel + +func FlatSlice[T any](source <-chan []T) <-chan T { + out := make(chan T, cap(source)) + + go func() { + defer close(out) + for slice := range source { + for _, v := range slice { + out <- v + } + } + }() + + return out +} + +func FlatChan[T any](source <-chan chan T) <-chan T { + out := make(chan T, cap(source)) + + go func() { + defer close(out) + for ch := range source { + for v := range ch { + out <- v + } + } + }() + + return out +}