schveiguy / iopipe

D language library for modular io
Boost Software License 1.0
77 stars 6 forks source link

add writeTo convenience function #39

Open schveiguy opened 1 year ago

schveiguy commented 1 year ago

If you are writing a pipe to a sink, you have to do:

someChain.push!(c => c.outputPipe(theSink));

This can be simplified (and looks nicer as):

someChain.writeTo(theSink);

It's a simple wrapper, but is way more approachable. Obviously if someone wants more than just an outputPipe, they have to use the first form. But this is probably going to be the most common way to build an output iopipe.

schveiguy commented 1 year ago

A further thought on this, theSink might need encoding. For example, if someChain has text, and theSink accepts only ubyte, then an encoding needs to happen. arraycast should be enough, since that's a reasonable default. Supporting transcoding between character types also is a possibility for sinks that accept characters but not the same width.

More complex encodings should be handled with the push function.

Also, writeTo might not seem correct, maybe pushTo?