pub fn cartesian_product<'a, T, F>(sets: &'a [&[T]], cb: F) where
    T: 'a,
    for<'r> F: FnMut(&'r [&'a T]) + 'a, 
Expand description

Create a cartesian product over given slice. The result will be a slice of borrowed T.

Parameters

  • sets A slice of slice(s) contains T elements.
  • 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::cartesian_product;
 
   cartesian_product(&[&[1, 2, 3], &[4, 5, 6]], |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);
   });