import std.conv : text; assert(fmtIf(true , () => 5, () => "apple").text == "5"); assert(fmtIf(false, () => 5, () => "apple").text == "apple"); // Scope lazy when? https://issues.dlang.org/show_bug.cgi?id=12647 auto division(int a, int b) { return fmtIf(b != 0, () => a / b, () => "NaN"); } assert(division(4, 2).text == "2"); assert(division(4, 0).text == "NaN");
Returns an object which, depending on a condition, is stringified as one of two objects. The two branches should themselves be passed as nullary functors, to enable lazy evaluation. Combines formattingFunctor, stringifiable, and select.