On Tuesday, 28 April 2015 at 10:46:54 UTC, Gary Willoughby wrote:
After reading the following thread:
http://forum.dlang.org/thread/nczgumcdfystcjqyb...@forum.dlang.org
I wondered if it was possible to write a classic fizzbuzz[1]
example using a UFCS chain? I've tried and failed.
[1]: http://en.wikipedia.org/wiki/Fizz_buzz
import std.stdio, std.algorithm, std.range, std.conv;
void main() {
immutable words = [3: "fizz", 5: "buzz"];
iota(1, 100).
map!((int i) {
immutable res = reduce!((a, b) => a ~ ((i % b == 0) ?
words[b] : ""))("", words.keys);
return res.empty ? i.to!string : res;
}).
writeln;
}
Atila