digitalmars.D.bugs - [Issue 15759] New: chunks should work with only an input range
- via Digitalmars-d-bugs (30/30) Mar 04 2016 https://issues.dlang.org/show_bug.cgi?id=15759
https://issues.dlang.org/show_bug.cgi?id=15759 Issue ID: 15759 Summary: chunks should work with only an input range Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: greeenify gmail.com 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? --
Mar 04 2016