How to force evaluation of range?

Taylor Hillegeist via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 12 12:43:24 PST 2016


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"));?

import std.stdio;
import std.path;
import std.file;
import std.uni;
import std.range;
import std.conv;
import std.algorithm;

void main(string[] Args){

     assert(Args.length>1,"Need a path to source files");
     assert(Args[1].isValidPath,"Path given is not Valid!");

     dirEntries(Args[1], SpanMode.depth)
         .filter!(f => f.name.endsWith(".c",".h"))
         .tee!(a => writeln("\n",a,"\n\t","=".repeat(80).join))
         .map!(a => a
             .File("r")
             .byLine
             .enumerate
             .filter!( l => l.value.byGrapheme.walkLength > 80)
             .tee!(a => writeln("Line: ",a.index,"\t",a.value))
          ).each!(a => a.each!("a")); //Force evaluation of every 
item

}


More information about the Digitalmars-d-learn mailing list