pub fn get_cartesian_for<T>(
objects: &[T],
degree: usize,
i: usize,
) -> Result<Vec<&T>, &str>Expand description
Get a cartesian product at specific location.
If objects is [1, 2, 3] and degree is 2 then
all possible result is [1, 1], [1, 2], [1, 3],
[2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]
§Parameters
objectsis a slice of an object.degreeis a degree of cartesian size.iis a specific location to get a combination.
§Examples
use permutator::get_cartesian_for;
let nums = [1, 2, 3];
get_cartesian_for(&nums, 2, 0); // Return Ok([1, 1])
get_cartesian_for(&nums, 2, 3); // Return Ok([2, 1])
get_cartesian_for(&nums, 2, 8); // Return Ok([3, 3])
get_cartesian_for(&nums, 2, 9); // Return Err("Parameter `i` is out of bound")
get_cartesian_for(&nums, 4, 0); // Return Err("Parameter `degree` cannot be larger than size of objects")