How to force evaluation of range?

Xinok via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 12 19:24:28 PST 2016


On Saturday, 13 February 2016 at 03:16:09 UTC, cym13 wrote:
> On Saturday, 13 February 2016 at 02:17:17 UTC, Xinok wrote:
>> On Friday, 12 February 2016 at 20:43:24 UTC, Taylor Hillegeist 
>> wrote:
>>> So I have this code and I have to add the element
>>> .each!(a => a.each!("a"));
>>> to the end in order for it to evaluate the range completely 
>>> and act like I expect it too. Is there a  better thing to put 
>>> in the place of
>>> .each!(a => a.each!("a"));?
>>>
>>> ...
>>
>> The following combination might work:
>>
>> .joiner.each;
>>
>> http://dlang.org/phobos/std_algorithm_iteration.html#.joiner
>>
>> http://dlang.org/phobos/std_algorithm_iteration.html#.each
>
> Why not just  .each;   ?

The thing he's trying to iterate over is a range of ranges. A 
single .each will only iterate over the outermost range so you 
need .joiner first to "flatten" the range, then you can use .each 
on that result.


More information about the Digitalmars-d-learn mailing list