Creature
A type declaration for an existing scala collection class and appender function is easier to implement than "collapse your own." As noted in the comments, this implementation probably won't be as productive as the “real” circular buffer, but it does its job with very little code:
import scala.collection.immutable
type CircularBuffer[T] = immutable.Vector[T]
def emptyCircularBuffer[T] : CircularBuffer[T] = immutable.Vector.empty[T]
def addToCircularBuffer[T](maxSize : Int)(buffer : CircularBuffer[T], item : T) : CircularBuffer[T] =
(buffer :+ item) takeRight maxSize
, "CircularBuffer" Vector, Vector (filter, map, flatMap ..) :
var intCircularBuffer = emptyCircularBuffer[Int]
//Vector(41)
intCircularBuffer = addToCircularBuffer(2)(intCircularBuffer, 41)
//Vector(41, 42)
intCircularBuffer = addToCircularBuffer(2)(intCircularBuffer, 42)
//Vector(42, 43)
intCircularBuffer = addToCircularBuffer(2)(intCircularBuffer, 43)
//Vector(42)
val evens : CircularBuffer[Int] = intCircularBuffer filter ( _ % 2 == 0)
:
def circularIndex[T](buffer : CircularBuffer[T])(index : Int) : T =
buffer(index % buffer.size)