Array of byLineCopy ranges behaves as they are byLine

Paul Backus snarwin at gmail.com
Mon Mar 11 18:00:58 UTC 2019


On Monday, 11 March 2019 at 17:33:31 UTC, HaraldZealot wrote:
> Ah yes, I forget about laziness of `map`. BTW, I have found 
> other solution, which is more fit to my initial intention.
>
> ```d
> ReturnType!(std.stdio.File.byLineCopy!(char, 
> immutable(char)))[] ranges;
> foreach(filename; args[1 .. $])
> {
>     ranges ~= File(filename, "r").byLineCopy;
> }
> ```

An easier way to do this is to use the library function 
`std.array.array`:

auto ranges = args[1..$].map!(a => File(a, "r").byLineCopy).array;


More information about the Digitalmars-d-learn mailing list