Possible to write a classic fizzbuzz example using a UFCS chain?
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 28 04:03:07 PDT 2015
Gary Willoughby:
> I wondered if it was possible to write a classic fizzbuzz[1]
> example using a UFCS chain? I've tried and failed.
Is this OK?
void main() {
import std.stdio, std.algorithm, std.range, std.conv,
std.functional;
100
.iota
.map!(i => ((i + 1) % 15).predSwitch(
0, "FizzBuzz",
3, "Fizz",
5, "Buzz",
6, "Fizz",
9, "Fizz",
10, "Buzz",
12, "Fizz",
/*else*/ i.text))
.reverseArgs!writefln("%-(%s\n%)");
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list