Back to Lo

It Seqtochannel

docs/data/it-seqtochannel.md

1.53.0579 B
Original Source

Converts an iter.Seq (or iter.Seq2) into a read-only channel. Items are sent on a buffered channel and the channel is closed when the sequence ends.

Examples:

go
// SeqToChannel: stream ints from a sequence
seq := it.Range(5) // 0..4
ch := it.SeqToChannel(2, seq)
var got []int
for v := range ch {
    got = append(got, v)
}
// got == []int{0, 1, 2, 3, 4}
go
// SeqToChannel2: stream key/value pairs as Tuple2
m := map[string]int{"a": 1, "b": 2}
kv := it.Entries(m)
ch := it.SeqToChannel2(1, kv)
for pair := range ch {
    // pair.A is key, pair.B is value
}