Convert program to 2020: replace foreach loop with map, filter and friends
thecybershadow.lists at gmail.com
Tue Mar 31 05:23:13 UTC 2020
On Tuesday, 31 March 2020 at 04:00:28 UTC, User wrote:
> I'd like to convert the following program to 2020 standards
> (i.e, replace the foreach block with a one-line code). I've
> tried much and I failed.
Here is how I'd do it.
Because the program downloads and then reads the local file
unconditionally, I replaced it with byLine. This allows it to
process the data as it is being downloaded, without first waiting
to download everything.
immutable URL =
immutable country = "Poland";
.map!(line => line.splitter(","))
.filter!(t => t.index == 0 || t.value.dropOne.front == country)
.map!(t => t.value)
More information about the Digitalmars-d-learn