www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11682] New: Lazier std.csv.csvReader

https://d.puremagic.com/issues/show_bug.cgi?id=11682

           Summary: Lazier std.csv.csvReader
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Given a "data.csv" file that contains:

1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16



With dmd 2.065alpha you can read its contents like this using csvReader:

void main() {
    import std.stdio, std.csv, std.file;
    "data.csv".readText.csvReader!int.writeln;
}


Output:

[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]


If the file is large you can also read the lines lazily (same output):

void main() {
    import std.stdio, std.csv, std.file, std.algorithm;
    "data.csv".File.byLine.map!(r => r.csvReader!int.front).writeln;
}


But I think csvReader should also support reading lines lazily like this:

"data.csv".File.csvReader!int.writeln;

Or something like this:

"data.csv".File.byLine.csvReader!int.writeln;

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 04 2013