On 17/08/15 00:33, Alex Parrill via Digitalmars-d wrote:
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);

Interesting, thanks for sharing that. I'm not at all surprised that an IO-based range should have similar issues to the one I describe; a comparable use-case I was thinking of was reading bytes from /dev/urandom.

My own concern was whether there was any sort of generic functionality for constructing lazy-front ranges like this; I'll share more on my own approach replying to Harald Zealot below.

Reply via email to