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?
Comment #1 by hsteoh — 2017-07-17T22:35:37Z
Comment #2 by github-bugzilla — 2017-08-01T22:00:25Z
Commit pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6826427ba55b9ae9a0f64f4489c359a851e08087 Fix issue 15759: Extend std.range.chunks to work with non-forward input ranges. Add input range example.
Comment #3 by github-bugzilla — 2017-08-16T13:24:29Z
Commit pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6826427ba55b9ae9a0f64f4489c359a851e08087 Fix issue 15759: Extend std.range.chunks to work with non-forward input ranges.
Comment #4 by github-bugzilla — 2018-01-05T13:30:54Z
Commit pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/6826427ba55b9ae9a0f64f4489c359a851e08087 Fix issue 15759: Extend std.range.chunks to work with non-forward input ranges.