Bug 15759 – chunks should work with only an input range
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-03-04T18:15:59Z
Last change time
2018-01-05T13:30:54Z
Keywords
pull
Assigned to
No Owner
Creator
greenify
Comments
Comment #0 by greeenify — 2016-03-04T18:15:59Z
It would be nice if `chunks` would accept only an InputRange too. Let me show you a common pattern that I often use:
// iterate over two lines in a pair and compute the difference between them
// 1 2
// 2 3
// => 2
stdin.byLineCopy.map!(x => x.splitter(' ').map!(to!int)).chunks(2)).map(x =>
abs(x.frontPop - x.front);
);
This currently doesn't compile, because `chunks` doesn't buffer, it saves the state of the forward range. However adding support for normal Input Ranges shouldn't can easily done using a local buffer - I already wrote the code at some point:
https://github.com/greenify/d-itertools/blob/4afbc804e8b50c797fa206969dc3b4934911a0b9/source/splitwise.d
I would be happy to wrap this up nicely and bring it into a phobos shape - any thoughts/concerns?