Specify variable type for range of associative arrays.

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 9 07:35:21 PDT 2015


On Sunday, 9 August 2015 at 14:23:33 UTC, Chris Davies wrote:
> The problem is, based on user input, I am optionally filtering 
> a list, possibly passing it through 0, 1, 2 or more filters 
> based on their input. Each successive filter runs on either the 
> original range or the result of the previous filter, if there 
> was one. Then I want to run a ussr-specified computation on the 
> final range... So it would be very nice to be able to reassign 
> the variable after each filter. Is there no good way to do that 
> other than with Generator?

You can use InputRange:
http://dlang.org/phobos/std_range_interfaces.html#InputRange

e.g.

     auto input = yourOriginalData.map!someTransformation;
     InputRange!string range;
     if(where != "")
         range = inputRangeObject(input.filter!(s => s == where));
     else
         range = inputRange(input);


More information about the Digitalmars-d-learn mailing list