[RFC] Add an operator for ranges to D. Pros and cons?
bearophile
bearophileHUGS at lycos.com
Wed Nov 7 06:11:38 PST 2012
Dejan Lekic:
> Dear D community, I do not know about You, but I certainly do
> not like writing code like:
>
> inRange.fooRange(param).barRange.
> .bazRange(param1, param2).outRange;
I suggest to format it this way, it's more readable:
auto something = inRange
.fooRange(param)
.barRange()
.bazRange(param1, param2)
.outRange();
> Therefore I would like to know what do you think about the idea
> of having additional operator exclusively made for ranges? This
> operator would make it obvious that data are "streamed" (lack
> of better term) among ranges.
>
> The first name I could come up with was "opArrow" but "opData"
> could also be okay, and operator would be either "~>" or "->".
>
> This would give us an obvious, unambiguous statement:
>
> Console.in ~> filter1(param) ~> fooRange ~> Console.out;
> // Console is an imaginary class/struct
I think it doesn't give a significant improvement. But maybe
there are more interesting use cases.
I'd like D ranges to support the "~" (using a template mixin to
give them such operator), that acts like chain. So instead of
writing:
range1.chain(range2)
You write:
range1 ~ range2
It's also nice to have lazy lists, maybe based on fibers, with
few operators to concat them, etc.
Bye,
bearophile
More information about the Digitalmars-d
mailing list