Closed mProjectsCode closed 11 months ago
Hi @mProjectsCode,
Thank you for your suggestion! It was implemented in v1.27.0
release.
cartesianProduct()
cartesianProductAsync()
cartesianProductWith()
cartesianProductWith()
import { set } from 'itertools-ts';
const numbers = [1, 2];
const letters = ['a', 'b'];
const chars = ['!', '?'];
for (const tuple of set.cartesianProduct(numbers, letters, chars)) {
console.log(tuple);
}
/*
[1, 'a', '!'],
[1, 'a', '?'],
[1, 'b', '!'],
[1, 'b', '?'],
[2, 'a', '!'],
[2, 'a', '?'],
[2, 'b', '!'],
[2, 'b', '?'],
*/
import { Stream } from "itertools-ts";
const numbers = [1, 2];
const result = Stream.of(numbers)
.cartesianProductWith(['a', 'b'], ['!', '?'])
.toArray();
/*
[
[1, 'a', '!'],
[1, 'a', '?'],
[1, 'b', '!'],
[1, 'b', '?'],
[2, 'a', '!'],
[2, 'a', '?'],
[2, 'b', '!'],
[2, 'b', '?'],
]
*/
thanks :)
It would be great to be able to iterate over the cartesian product of multiple lists.