pub trait IterArrayChunks: Iterator {
    // Provided methods
    fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N> 
       where Self: Sized { ... }
    fn arrays<const N: usize>(self) -> ArrayChunks<Self, N> 
       where Self: Sized { ... }
}
Available on crate feature array_chunks only.
Expand description

An extension trait that provides the array_chunks method for iterators.

Note: the method provided here has a nightly API: Iterator::array_chunks. The nightly API handles remainders better and will likely have better performance, so it should be preferred if possible.

Provided Methods§

source

fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
where Self: Sized,

Returns an iterator over N elements of the iterator at a time.

The chunks do not overlap. If N does not divide the length of the iterator, then the last up to N-1 elements will be omitted.

Panics

If called with N = 0.

Examples

Basic usage:

use itermore::IterArrayChunks;

let mut iter = "lorem".chars().array_chunks();
assert_eq!(iter.next(), Some(['l', 'o']));
assert_eq!(iter.next(), Some(['r', 'e']));
assert_eq!(iter.next(), None);
use itermore::IterArrayChunks;

let data = [1, 1, 2, -2, 6, 0, 3, 1];
//          ^-----^  ^------^
for [x, y, z] in data.iter().array_chunks() {
    assert_eq!(x + y + z, 4);
}
source

fn arrays<const N: usize>(self) -> ArrayChunks<Self, N>
where Self: Sized,

Identical to array_chunks but doesn’t collide with the standard library name.

Implementors§

source§

impl<I> IterArrayChunks for I
where I: Iterator + ?Sized,