Another new io library

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 18 08:36:37 PST 2016


On 2/18/16 11:07 AM, Wyatt wrote:
> On Wednesday, 17 February 2016 at 06:45:41 UTC, Steven Schveighoffer wrote:
>>
>> foreach(line; (new IODevice(0)).bufferedInput
>>     .asText!(UTFType.UTF8)
>>     .byLine
>>     .asInputRange)
>>    // handle line
>>
> This looks pretty all-right so far.  Would something like this work?
>
> foreach(pollItem; zmqSocket.bufferedInput
>      .as!(zmqPollItem)
>      .asInputRange)

Yes, that is the intent. All without copying.

Note, asInputRange may not do what you want here. If multiple 
zmqPollItems come in at once (I'm not sure how your socket works), the 
input range's front will provide the entire window of data, and flush it 
on popFront.

I'll also point at arrayCastPipe 
(https://github.com/schveiguy/iopipe/blob/master/source/iopipe/bufpipe.d#L399), 
which simply casts the input array window to a new type of array window 
(if the items are coming in binary form).

I'm thinking I'll change the name byInputRange to byWindow, and add a 
byElement for an element-wise input range.

>
>> 6. There is a concept in here I called "valves". It's very weird, but
>> it allows unifying input and output into one seamless chain. In fact,
>> I can't think of how I could have done output in this regime without
>> them. See the convert example application for details on how it is used.
>>
> This... might be cool?  It bears some similarity to my own ideas.  I'd
> like to see more examples, though.

I'm hoping people can come up with ideas for other uses for them. I 
really like the concept, but the only use case I have right now is 
output streams.

It would be cool to see if there's a use case for multiple valves.

-Steve


More information about the Digitalmars-d mailing list