class Fibonacci extends Iterator[Int] { var x = 0 var y = 1 override def hasNext = true override def next = { val tmp = x; x = y; y += tmp; tmp } }