www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13590] New: [Enh] Add std.algorithm.iterate

https://issues.dlang.org/show_bug.cgi?id=13590

          Issue ID: 13590
           Summary: [Enh] Add std.algorithm.iterate
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

In using http://dlang.org/phobos/std_stdio.html#.File.byChunk, it turns out to
be rather clumsy to get things character-by-character, one has to write a loop.
This is not how ranges are supposed to work.

It exposes a more general problem - given a Range of a Range of Elements, how
does one iterate over Elements?

The solution is a new algorithm - iterate.

And that's all it does - one could write .byChunk.iterate and voila! one is
getting ubytes by ubyte. iterate takes a template argument of the number of
Elements it should produce for each front():

    .byChunk.iterate!4   // get ubyte[4]

iterate should produce results by value, not by ref. This is because byChunk
produces references to ephemeral data.

iterate asserts if the number of elements does not evenly divide into the
.byChunk size (or should it throw?). Obviously, by 1 should not assert or
throw.

Pulling data out 4 bytes at a time is useful, for example, to read data as a
sequence of ints.

iterate should be lazy.

--
Oct 08 2014