itertools icon indicating copy to clipboard operation
itertools copied to clipboard

Add `tuple_permutations`

Open JonathanBrouwer opened this issue 1 year ago • 4 comments

There is the combinations() and tuple_combinations() functions, I'm however missing the tuple_permutations() function.

Is there a reason this couldn't exist? If not, I might even be open to implementing it depending on how much macro hackery is needed

JonathanBrouwer avatar Dec 08 '24 09:12 JonathanBrouwer

It may be easier to add array_permutations() if you want to avoid macro hackery.

ronnodas avatar Jan 04 '25 12:01 ronnodas

That's true and in general probably nicer to use than tuples, thanks for the pointer!

JonathanBrouwer avatar Jan 04 '25 13:01 JonathanBrouwer

It seems possible to share most of the code from permutations(), similar to the array_combinations() implementation. In that case we probably want to start with:

impl<T> PoolIndex<T> for Box<[usize]> {
    type Item = Vec<T>;

   ...
}

and then make PermutationState generic. (Aside: I'm not sure why PermutationState::Loaded.indices is a Box<[usize]> instead of a Vec<usize>.)

ronnodas avatar Jan 06 '25 20:01 ronnodas

Aside: I'm not sure why PermutationState::Loaded.indices is a Box<[usize]> instead of a Vec<usize>.

Canonically we use Box<[usize]> if the size stays unchanged.

phimuemue avatar Jan 07 '25 07:01 phimuemue