View source code
Display the source code in std/range.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
std.range.chunks
- multiple declarations
- Function chunks
- Struct Chunks
Function chunks
This range iterates over fixed-sized chunks
of size
of a
chunkSize
range. source
Source
must be a forward range.
If !isInfinite!Source
and source.walkLength
is not evenly
divisible by
, the back element of this range will contain
fewer than chunkSize
elements.
chunkSize
Prototype
Chunks!Source chunks(Source)( Source source, size_t chunkSize ) if (isForwardRange!Source);
Example
import std.algorithm : equal; auto source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; auto chunks = chunks(source, 4); assert(chunks[0] == [1, 2, 3, 4]); assert(chunks[1] == [5, 6, 7, 8]); assert(chunks[2] == [9, 10]); assert(chunks.back == chunks[2]); assert(chunks.front == chunks[0]); assert(chunks.length == 3); assert(equal(retro(array(chunks)), array(retro(chunks))));
Struct Chunks
This range iterates over fixed-sized chunks
of size chunkSize
of a
source
range. Source
must be a forward range.
If !isInfinite!Source
and source.walkLength
is not evenly
divisible by chunkSize
, the back element of this range will contain
fewer than chunkSize
elements.
Constructors
Name | Description |
---|---|
this
|
Standard constructor |
Properties
Name | Type | Description |
---|---|---|
front
[get]
|
|
Forward range primitives. Always present. |
save
[get]
|
typeof(this) |
Forward range primitives. Always present. |
Methods
Name | Description |
---|---|
popFront
|
Forward range primitives. Always present. |
Example
import std.algorithm : equal; auto source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; auto chunks = chunks(source, 4); assert(chunks[0] == [1, 2, 3, 4]); assert(chunks[1] == [5, 6, 7, 8]); assert(chunks[2] == [9, 10]); assert(chunks.back == chunks[2]); assert(chunks.front == chunks[0]); assert(chunks.length == 3); assert(equal(retro(array(chunks)), array(retro(chunks))));
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.