Possible to write a classic fizzbuzz example using a UFCS chain?

safety0ff via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 30 07:45:46 PDT 2015


Just for fun:

//     map,           join,      text,     iota,      writeln,   
tuple
import std.algorithm, std.array, std.conv, std.range, std.stdio, 
std.typecons;

void main()
{
   iota(1,100)
   .map!(a => tuple(a, a % 3 == 0 ? 0 : 4, a % 5 == 0 ? 8 : 4))
   .map!(a => a[1] == a[2] ? a[0].text : "fizzbuzz"[a[1] .. a[2]])
   .join(", ")
   .writeln;
}


More information about the Digitalmars-d-learn mailing list