I was being intentionally verbose so that readers not familiar with Scala or the collections types/methods used would have an easier time following it. I also was avoiding use of pattern matching as they are cousins to conditionals IMHO.
However, below is another version which employs idioms more commonly found:
object Fizzbuzz
{
val fizzes = None :: None :: Some ("Fizz") :: Nil;
val buzzes = None :: None :: None :: None :: Some ("Buzz") :: Nil;
def apply (amount : Int) : TraversableOnce[String] =
{
val alternates = Stream.continually (fizzes).flatten
.zip (Stream.continually (buzzes).flatten)
.take (amount)
.toArray;
0.until (amount).map { n =>
alternates (n) match {
case (Some (f), Some (b)) => f + b;
case (Some (f), None) => f;
case (None, Some (b)) => b;
case _ => (n + 1).toString
}
}
}
}
Fizzbuzz (100).foreach (println);