Rust: unique combinations preserving order
01:51 30 Dec 2025

I have a list of elements like [1, 1, 2, 2, 3, 4, 5]. I want to iterate through all the k-length sub-lists of this list, such that identical combinations do not occur, that is I don't get [1, 3, 4] twice because the element 1 is repeated twice, but I do get [1, 1, 2], and I want to preserve the order of the elements, so that I don't get [1, 2, 1].

Is there a ready-made function for that (I may not know the proper mathematical name of the permutation), or do I have to write it myself?

math rust