This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
ProgrammingInScala/Covariance/src/Coda.scala

20 lines
465 B
Scala

/**
* 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)
}
}