Back to Lo

It Channeltoseq

docs/data/it-channeltoseq.md

1.53.0561 B
Original Source

SeqToChannel2 returns a read-only channel of key-value tuple elements from a sequence.

go
collection := func(yield func(int, string) bool) {
    yield(1, "a")
    yield(2, "b")
}

ch := it.SeqToChannel2(10, collection)
for tuple := range ch {
    fmt.Printf("%d: %s\n", tuple.A, tuple.B)
}
// 1: a
// 2: b

ChannelToSeq returns a sequence built from channel items. Blocks until channel closes.

go
ch := make(chan int, 3)
ch <- 1
ch <- 2
ch <- 3
close(ch)

seq := it.ChannelToSeq(ch)
for item := range seq {
    fmt.Println(item)
}
// 1
// 2
// 3