That's a slick way to remove the conditionals indeed. Inspired by it, here's a Scala version (checked with v2.11):
object Fizzbuzz
{
val fizzes = List (None, None, Some ("Fizz")).toStream;
val buzzes = List (None, None, None, None, Some ("Buzz")).toStream;
val reducer : (Option[String], Option[String]) => Option[String] =
(a, b) => Option ((a ++ b).mkString).filterNot (_.isEmpty);
def apply (amount : Int) : Seq[String] =
Stream.continually (fizzes)
.flatten
.zip (Stream.continually (buzzes).flatten)
.map (reducer.tupled)
.zipWithIndex
.map {
case (s, n) => s.getOrElse ((n + 1).toString);
}
.take (amount);
}
Fizzbuzz (100).foreach (println)