32 lines
453 B
Go
32 lines
453 B
Go
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
|
|
}
|