Back to Lo

It Crossjoinbyx

docs/data/it-crossjoinbyx.md

1.53.0614 B
Original Source

Combines every item from multiple lists (cartesian product) using a callback function to transform the results. Returns an empty sequence if any input sequence is empty.

Variants: CrossJoinBy2..CrossJoinBy9

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