byChunk odd behavior?
Hanh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 22 20:17:05 PDT 2016
Thanks for your help everyone.
I agree that the issue is due to the misusage of an InputRange
but what is the semantics of 'take' when applied to an
InputRange? It seems that calling it invalidates the range; in
which case what is the recommended way to get a few bytes and
keep on advancing.
For instance, to read a ushort, I use
range.read!(ushort)()
Unfortunately, it reads a single value.
For now, I use a loop
foreach (i; 0..N) {
buffer[i] = range.front;
range.popFront();
}
Is there a more idiomatic way to do the same thing?
In Scala, 'take' consumes bytes from the iterator. So the same
code would be
buffer = range.take(N).toArray
More information about the Digitalmars-d-learn
mailing list