EvenChunks

This range splits a source range into chunkCount chunks of approximately equal length. Source must be a forward range with known length.

Unlike chunks, evenChunks takes a chunk count (not size). The returned range will contain zero or more source.length / chunkCount + 1 elements followed by source.length / chunkCount elements. If source.length < chunkCount, some chunks will be empty.

chunkCount must not be zero, unless source is also empty.

Constructors

this
this(Source source, size_t chunkCount)

Standard constructor

Members

Functions

opIndex
auto opIndex(size_t index)
opSlice
typeof(this) opSlice(size_t lower, size_t upper)
popBack
void popBack()

Indexing, slicing and bidirectional operations and range primitives. Provided only if hasSlicing!Source is true.

popFront
void popFront()

Forward range primitives. Always present.

Properties

back
auto back [@property getter]

Indexing, slicing and bidirectional operations and range primitives. Provided only if hasSlicing!Source is true.

empty
bool empty [@property getter]

Forward range primitives. Always present.

front
auto front [@property getter]

Forward range primitives. Always present.

length
size_t length [@property getter]

Length

save
typeof(this) save [@property getter]

Forward range primitives. Always present.

Examples

import std.algorithm.comparison : equal;
auto source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
auto chunks = evenChunks(source, 3);
assert(chunks[0] == [1, 2, 3, 4]);
assert(chunks[1] == [5, 6, 7]);
assert(chunks[2] == [8, 9, 10]);

Meta