Trait itermore::IterCombinations
source · pub trait IterCombinations: Iterator {
// Provided method
fn combinations(self, k: usize) -> Combinations<Self> ⓘ
where Self: Sized,
Self::Item: Clone { ... }
}
Available on crate feature
combinations
only.Expand description
An extension trait that provides the combinations
method for iterators.
Provided Methods§
sourcefn combinations(self, k: usize) -> Combinations<Self> ⓘ
fn combinations(self, k: usize) -> Combinations<Self> ⓘ
Returns an iterator adaptor that iterates over k
length combinations
of all the elements in the underlying iterator.
The iterator is consumed as elements are required. In the first
iteration k
elements will be consumed by the iterator.
Panics
If called with k = 0
.
Examples
Basic usage:
use itermore::IterCombinations;
let mut iter = "abcd".chars().combinations(3);
assert_eq!(iter.next(), Some(vec!['a', 'b', 'c']));
assert_eq!(iter.next(), Some(vec!['a', 'b', 'd']));
assert_eq!(iter.next(), Some(vec!['a', 'c', 'd']));
assert_eq!(iter.next(), Some(vec!['b', 'c', 'd']));
assert_eq!(iter.next(), None);