pub fn iter_windows<I: Iterator>(window_size: usize, xs: I) -> IterWindows<I>Notable traits for IterWindows<I>impl<I: Iterator> Iterator for IterWindows<I> where
    I::Item: Clone
type Item = VecDeque<I::Item>;
where
    I::Item: Clone
Expand description

Returns windows of $n$ adjacent elements of an iterator, advancing the window by 1 in each iteration. The values are cloned each time a new window is generated.

The output length is $n - k + 1$, where $n$ is xs.count() and $k$ is window_size.

Panics

Panics if window_size is 0.

Examples

extern crate itertools;

use itertools::Itertools;
use malachite_base::iterators::iter_windows;

let xs = 0..=5;
let windows = iter_windows(3, xs).map(|ws| ws.iter().cloned().collect_vec()).collect_vec();
assert_eq!(
    windows.iter().map(Vec::as_slice).collect_vec().as_slice(),
    &[&[0, 1, 2], &[1, 2, 3], &[2, 3, 4], &[3, 4, 5]]
);