D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15759 - chunks should work with only an input range
Summary: chunks should work with only an input range
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2016-03-04 18:15 UTC by Seb
Modified: 2018-01-05 13:30 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Seb 2016-03-04 18:15:59 UTC
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 hsteoh 2017-07-17 22:35:37 UTC
https://github.com/dlang/phobos/pull/5624
Comment 2 github-bugzilla 2017-08-01 22:00:25 UTC
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 github-bugzilla 2017-08-16 13:24:29 UTC
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 github-bugzilla 2018-01-05 13:30:54 UTC
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.