A little help with Ranges
Merlin Diavova
md at mdiavov.com
Fri Aug 27 04:41:38 UTC 2021
On Friday, 27 August 2021 at 04:01:19 UTC, Ali Çehreli wrote:
> On 8/26/21 7:17 PM, Merlin Diavova wrote:
>
>> [...]
>
> Then the operations downstream will not produce any results.
> For example, the array will be empty below:
>
> import std.stdio;
> import std.range;
> import std.algorithm;
> import std.string;
> import std.functional;
>
> void main() {
> auto significantLines = stdin
> .byLineCopy
> .map!strip
> .filter!(not!empty)
> .filter!(line => line.front != '#')
> .array;
>
> if (significantLines.empty) {
> writeln("There were no significant lines.");
>
> } else {
> writefln!"The lines: %-(\n%s%)"(significantLines);
> }
> }
>
> Ali
And there it is!
I was missing
```d
.filter!(not!empty)
```
My code now works exactly how I wanted. Thanks!
More information about the Digitalmars-d-learn
mailing list