std.range pipelike interface, inverting OutputStreams?

cy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 12 19:15:55 PDT 2016


I was trying to use std.regex, and it takes an output stream to 
pump the result to, which is great, but I wanted to perform TWO 
replacements, one with the output of the previous, with data that 
might be a tricky size to cache redundantly.

So, ideally when you do something like regexp replacing, you'd 
have a function like:
InputRange replaceThingy(InputRange source, someregex, 
somereplacer);

It doesn't do that, unfortunately, so I can't easily chain 
replacements. But couldn't I do a thing like...

InputRange pipe(void delegate(ref OutputRange)) { ? }

and then just...
   auto result = pipe((sink) => replaceAllInto(sink, data, 
firstmatch, firstreplacer));
   auto result2 = pipe((sink) => replaceAllInto(sink, result, 
secondmatch, secondreplacer));
   copy(result2,stdout);

... or something like that? Has that been done before? Can it be 
done?

I'm pretty sure any algorithm that takes an output stream can be 
transformed into an algorithm that provides an input stream, but 
I'm not sure if I'd be reinventing the wheel here, or if my 
assumptions are seriously off.

Hoping to avoid weird stuff like context switches... eh.


More information about the Digitalmars-d-learn mailing list