[−][src]Function permutator::self_cartesian_product
pub fn self_cartesian_product<'a, T, F>(set: &'a [T], n: usize, cb: F) where
T: 'a,
F: FnMut(&'r [&'a T]) + 'a,
Create a cartesian product over itself. The result will be a slice
of borrowed T
.
Parameters
set
A slice of slice(s) containsT
elements.n
How many time to create a product overset
cb
A callback function. It will be called on each product.
Return
A function return a slice of borrowed T
element out of parameter sets
.
It return value as parameter of callback function cb
.
Examples
To print all cartesian product between [1, 2, 3] and [4, 5, 6].
use permutator::self_cartesian_product; self_cartesian_product(&[1, 2, 3], 3, |product| { // First called will receive [1, 4] then [1, 5] then [1, 6] // then [2, 4] then [2, 5] and so on until [3, 6]. println!("{:?}", product); });