Open
Description
Proposal Details
#61899 would add iteration related functions to slices, and #61900 does the same for maps. There should also be a package with channel iteration helpers. I propose adding package chans with chans.Seq:
package chans
import "iter"
// Seq returns an iterator that yields the values of ch until it is closed.
func Seq[T any](ch <-chan T) iter.Seq[T] {
return func(yield func(T) bool) {
for v := range ch {
if !yield(v) {
return
}
}
}
}
An example use would be s := slices.Collect(chans.Seq(ch))
as a convenient way to collect all values from a channel into a slice.
Metadata
Metadata
Assignees
Type
Projects
Status
Incoming