Truly lazy ranges, transient .front, and std.range.Generator
Alex Parrill via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 16 15:33:32 PDT 2015
On Saturday, 15 August 2015 at 10:06:13 UTC, Joseph Rushton
Wakeling wrote:
> ...
I had this issue recently when reading from a command-line-style
TCP connection; I needed to read the line up to the \n separator,
but consuming the separator meant waiting for the next byte that
would never arrive unless a new command was sent.
So I made a wrapper range that evaluates the wrapped range's
popFront only when front/empty is first called ("just in time").
Source code here:
https://gist.github.com/ColonelThirtyTwo/0dfe76520efcda02d848
You can throw it in a UFCS chain anywhere except (for some
reason) after something that takes a delegate template parameter
like map. For example:
auto reader = SocketReader(socket).joiner.jitRange.map!(byt
=> cast(char) byt);
More information about the Digitalmars-d
mailing list