Skip to content

Can the order of Combinations be relied on? #819

@ryanavella

Description

@ryanavella

Does itertools::Combinations makes any guarantees about the order in which it yields combinations?

The docs provide this example:

use itertools::Itertools;

let it = (1..5).combinations(3);
itertools::assert_equal(it, vec![
    vec![1, 2, 3],
    vec![1, 2, 4],
    vec![1, 3, 4],
    vec![2, 3, 4],
]);

Which at a glance is constructing the combinations by "indexing" the iterator (1..5) with lexicographically sorted indices [0, 1, 2], [0, 1, 3], [0, 2, 3], and [1, 2, 3].

I am wondering if this is something I can rely on, or if it is an implementation detail that should not be relied on?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions