[][src]Trait const_combinations::IterExt

pub trait IterExt: Iterator + Sized where
    Self::Item: Clone
{ pub fn combinations<const K: usize>(self) -> Combinations<Self, K>

Notable traits for Combinations<I, K>

impl<I, const K: usize> Iterator for Combinations<I, K> where
    I: Iterator,
    I::Item: Clone
type Item = [I::Item; K];
{ ... }
pub fn permutations<const K: usize>(self) -> Permutations<Self, K>

Notable traits for Permutations<I, K>

impl<I, const K: usize> Iterator for Permutations<I, K> where
    I: Iterator,
    I::Item: Clone
type Item = [I::Item; K];
{ ... } }

An extension trait adding combinations and permutations to Iterator.

Provided methods

pub fn combinations<const K: usize>(self) -> Combinations<Self, K>

Notable traits for Combinations<I, K>

impl<I, const K: usize> Iterator for Combinations<I, K> where
    I: Iterator,
    I::Item: Clone
type Item = [I::Item; K];
[src]

Return an iterator adaptor that iterates over the k-length combinations of the elements from an iterator.

The iterator produces a new array per iteration, and clones the iterator elements. If K is greater than the length of the input iterator the resulting iterator adaptor will yield no items.

Examples

use const_combinations::IterExt;

let mut combinations = (1..5).combinations();
assert_eq!(combinations.next(), Some([1, 2, 3]));
assert_eq!(combinations.next(), Some([1, 2, 4]));
assert_eq!(combinations.next(), Some([1, 3, 4]));
assert_eq!(combinations.next(), Some([2, 3, 4]));
assert_eq!(combinations.next(), None);

Note: Combinations does not take into account the equality of the iterated values.

let mut combinations = vec![1, 2, 2].into_iter().combinations();
assert_eq!(combinations.next(), Some([1, 2])); // Note: these are the same
assert_eq!(combinations.next(), Some([1, 2])); // Note: these are the same
assert_eq!(combinations.next(), Some([2, 2]));
assert_eq!(combinations.next(), None);

pub fn permutations<const K: usize>(self) -> Permutations<Self, K>

Notable traits for Permutations<I, K>

impl<I, const K: usize> Iterator for Permutations<I, K> where
    I: Iterator,
    I::Item: Clone
type Item = [I::Item; K];
[src]

Return an iterator adaptor that iterates over the k-length permutations of the elements from an iterator.

The iterator produces a new array per iteration, and clones the iterator elements. If K is greater than the length of the input iterator the resulting iterator adaptor will yield no items.

Examples

let mut permutations = (0..3).permutations();
assert_eq!(permutations.next(), Some([0, 1]));
assert_eq!(permutations.next(), Some([1, 0]));
assert_eq!(permutations.next(), Some([0, 2]));
assert_eq!(permutations.next(), Some([2, 0]));
assert_eq!(permutations.next(), Some([1, 2]));
assert_eq!(permutations.next(), Some([2, 1]));
assert_eq!(permutations.next(), None);

Note: Permutations does not take into account the equality of the iterated values.

let mut permutations = vec![2, 2].into_iter().permutations();
assert_eq!(permutations.next(), Some([2, 2])); // Note: these are the same
assert_eq!(permutations.next(), Some([2, 2])); // Note: these are the same
assert_eq!(permutations.next(), None);
Loading content...

Implementors

impl<I> IterExt for I where
    I: Iterator,
    I::Item: Clone
[src]

Loading content...