Product of two slices
nikicat opened this issue · 3 comments
nikicat commented
Hello, I didn't find it in the docs - how to make the product of two slices (of different types in a general case) using this library? Is it possible?
Something like:
In [4]: list(itertools.product([1,2], ['a', 'b']))
Out[4]: [(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b')]
mowshon commented
@nikicat yes, it's possible. You need to use a slice of type any
:
package main
import (
"fmt"
"github.com/mowshon/iterium"
)
func main() {
chars := []any{1, 2, "a", "b"}
data := iterium.Product(chars, 2)
step := 0
for value := range data.Chan() {
fmt.Println(step, ")", value)
step += 1
}
}
Output:
1 ) [1 1]
2 ) [1 2]
3 ) [1 a]
4 ) [1 b]
5 ) [2 1]
6 ) [2 2]
7 ) [2 a]
8 ) [2 b]
9 ) [a 1]
10 ) [a 2]
11 ) [a a]
12 ) [a b]
13 ) [b 1]
14 ) [b 2]
15 ) [b a]
16 ) [b b]