optional process

Taylor R Hillegeist taylorh140 at gmail.com
Fri Nov 29 15:39:35 UTC 2019


On Friday, 29 November 2019 at 15:24:31 UTC, Paul Backus wrote:
> On Friday, 29 November 2019 at 15:17:35 UTC, Taylor R 
> Hillegeist wrote:
>> I know phobos has choose which is close.
>> But what I want is something like:
>>
>> bool sortOutput;
>>
>> if(sortOutput){
>> read(Textfile)
>>    .splitter("\n")
>>    .filter(a=>a.contains("data))
>>    .doif(sortOutput,sort!("a < b"))
>>    .writeln();
>
> import std.functional: pipe;
>
> bool sortOutput;
>
> read(Textfile)
>    .splitter("\n")
>    .filter!(a=>a.contains("data))
>    .pipe!((output) {
>       if (sortOutput)
>          return output.sort!("a < b");
>       else
>          return output;
>    })
>    .writeln(); // maybe you meant each!writeln ?

That is actually exactly the kind of thing I was looking for. (it 
gets the job done without repeats) I would still like it to be in 
the first form though e.g. doif. it would keep the code cleaner.
Thank you for this.  (also yes I just made up the example so 
.each!writeln is appropriate it would be surprising to me if that 
was the only error)



More information about the Digitalmars-d-learn mailing list