pub trait IteratorBatchExt: Iterator {
    // Provided methods
    fn batch_exact<Size: Dim>(self, size: Size) -> Batcher<Size, Self>
       where Self: Sized { ... }
    fn batch_with_last(self, size: usize) -> BatcherWithLast<Self>
       where Self: Sized { ... }
    fn batch<Size: Dim>(self, size: Size) -> Batcher<Size, Self>
       where Self: Sized { ... }
}
Expand description

Create batches of items from an Iterator

Provided Methods§

source

fn batch_exact<Size: Dim>(self, size: Size) -> Batcher<Size, Self>where Self: Sized,

Return an Iterator where the items are either:

  • [Self::Item; N], if Size is Const<N>
  • Vec<Self::Item>, if Size is usize.

If the last batch contains fewer than size items, it is not returned. To include this batch, use IteratorBatchExt::batch_with_last.

Const batches:

let items: Vec<[usize; 5]> = (0..12).batch_exact(Const::<5>).collect();
assert_eq!(&items, &[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]);

Runtime batches:

let items: Vec<Vec<usize>> = (0..12).batch_exact(5).collect();
assert_eq!(&items, &[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]);
source

fn batch_with_last(self, size: usize) -> BatcherWithLast<Self>where Self: Sized,

Returns an Iterator containing all data in the input iterator grouped into batches of maximum length size. All batches except the last contain exactly size elements, and all batches contain at least one element.

Example:

let items: Vec<Vec<usize>> = (0..12).batch_with_last(5).collect();
assert_eq!(&items, &[vec![0, 1, 2, 3, 4], vec![5, 6, 7, 8, 9], vec![10, 11]]);
source

fn batch<Size: Dim>(self, size: Size) -> Batcher<Size, Self>where Self: Sized,

👎Deprecated

Deprecated, use IteratorBatchExt::batch_exact instead.

Implementors§