The OpenD Programming Language

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.

EvenChunks!Source
evenChunks
(
Source
)
(
Source source
,
size_t chunkCount
)
if (
isForwardRange!Source &&
hasLength!Source
)

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