Back to Lo

It Zipbyx

docs/data/it-zipbyx.md

1.53.0637 B
Original Source

Creates a sequence of transformed elements from multiple sequences using a transform function. When sequences are different lengths, shorter sequences are padded with zero values before transformation.

Variants: ZipBy2..ZipBy9

go
seq1 := func(yield func(int) bool) {
    _ = yield(1)
    _ = yield(2)
    _ = yield(3)
}
seq2 := func(yield func(string) bool) {
    _ = yield("a")
    _ = yield("b")
}
zipped := it.ZipBy2(seq1, seq2, func(i int, s string) string {
    return fmt.Sprintf("%d-%s", i, s)
})
var result []string
for item := range zipped {
    result = append(result, item)
}
// result contains ["1-a", "2-b", "3-"]