Newer
Older
enum List[+A]:
case Nil
case Cons(_head: A, _tail: List[A])
def head: A = this match
case Nil => sys.error("head of empty list")
case Cons(a, _) => a
/** removes the first element of a list and returns the rest */
/** returns all but the last element of a list */
def setHead[AA >: A](head: AA): List[AA] = ???
/** recurses through the list, combining elements with the given function
* Uncomment the annotation to enable checking for tail-recursiveness */
//@annotation.tailrec
final def foldLeft[B](z: B)(f: (B, A) => B): B = ???
/** construct a list by passing elements
*
* Remember: `apply` makes the object behave like a function,
* you can call it as `List(elem1, elem2,...)`
**/