mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
1.0 KiB
1.0 KiB
name, slug, sourceRef, category, subCategory, signatures, playUrl, variantHelpers, similarHelpers, position
| name | slug | sourceRef | category | subCategory | signatures | playUrl | variantHelpers | similarHelpers | position | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| SeqToChannel2 | channeltoseq | it/channel.go#L26 | it | channel |
|
https://go.dev/play/p/IXqSs2Ooqpm |
|
|
10 |
SeqToChannel2 returns a read-only channel of key-value tuple elements from a sequence.
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.
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