Using lazy code to process large files
Martin DraĊĦar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 2 04:44:30 PDT 2017
Hi,
I am struggling to use a lazy range-based code to process large text
files. My task is simple, i.e., I can write a non-range-based code in a
really short time, but I wanted to try different approach and I am
hitting a wall after wall.
Task: read a csv-like input, take only lines starting with some string,
split by a comma, remove leading and trailing whitespaces from splitted
elements, join by comma again and write to an output.
My attempt so far:
alias stringStripLeft = std.string.stripLeft;
auto input = File("input.csv");
auto output = File("output.csv");
auto result = input.byLine()
.filter!(a => a.startsWith("..."))
.map!(a => a.splitter(","))
.stringStripleft // <-- errors start here
.join(",");
output.write(result);
Needless to say, this does not compile. Basically, I don't know how to
feed MapResults to splitter and then sensibly join it.
Thank you for any hint.
Martin
More information about the Digitalmars-d-learn
mailing list