Feedback on Streams concept, similar to Ranges

Monkyyy crazymonkyyy at gmail.com
Wed May 17 00:50:19 UTC 2023


On Monday, 15 May 2023 at 09:53:22 UTC, Andrew wrote:
> So I've been working on a small side project for the last few 
> days, and I think that it's gotten to the point where I think 
> that it's ready to be reviewed/critiqued.
>
> The project is available on GitHub here: 
> https://github.com/andrewlalis/streams
>
> It introduces the concept of **Streams**, which is anything 
> with either of the following function signatures:
> - `int read(T[] buffer)` - this is an **input stream**.
> - `int write(T[] buffer)` - this is an **output stream**.
>
> The README.md on the project's homepage describes the 
> motivation in more detail, but in short, I'm not 100% satisfied 
> with Phobos' ranges, and I think that streams could be 
> introduced as a lower-level primitive that's also more familiar 
> to programmers coming from a variety of other languages, while 
> still trying to be as idiomatically D as possible.
>
> Just for the sake of demonstration, here's an example of using 
> streams to transfer the contents of a file to some arbitrary 
> output stream. Of course pretty much anything done with streams 
> can also be done with ranges, but I think that the simpler 
> interface will make some things more ergonomic.
>
> ```d
> import streams;
>
> void readFileTo(S)(string filename, S stream) if 
> (isOutputStream!(S, ubyte)) {
>   import std.stdio;
>   auto fIn = FileInputStream(filename);
>   transferTo(fIn, stream);
> }
> ```
>
> So, I'd appreciate if anyone could take a look at my project, 
> tell me if you think this is a good idea or not, if I should 
> introduce a DIP for this change if added to Phobos (I know the 
> DIP process is closed at the moment), or if you have any other 
> feedback for this.

How would this help me with say rendering video and enforcing 
frames are syncef? If T[] doesnt have any flexable logic?



More information about the Digitalmars-d mailing list