/** * Created by claudio on 26/12/16. */ trait Coda[T] { def head: T def tail: Coda[T] def accoda(elem: T): Coda[T] } object Coda { def apply[T](cose: T*): Coda[T] = new CodaImpl(cose.toList, Nil) def apply[T](list: List[T]): Coda[T] = new CodaImpl(list, Nil) private class CodaImpl[T](private val heading: List[T], private val tailing: List[T]) extends Coda[T]{ def head: T = heading.head def tail = Coda(heading.tail ::: tailing) } }