optional process

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


When using the standard library. and making command-line 
applications I find myself wanting optional processes in line. 
for me, this typically makes the following structure.

bool sortOutput;

if(sortOutput){
read(Textfile)
    .splitter("\n")
    .filter(a=>a.contains("data))
    .sort!("a < b").writeln();

}else{

read(Textfile)
    .splitter("\n")
    .filter(a=>a.contains("data))
    .writeln();
}

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();


More information about the Digitalmars-d-learn mailing list