Skip to content
Snippets Groups Projects
Commit 2687b677 authored by Manos Koukoutos's avatar Manos Koukoutos
Browse files

tailOption in List

parent 419597e3
Branches
Tags
No related merge requests found
......@@ -40,6 +40,12 @@ sealed abstract class List[T] {
case Cons(h, _) => Some(h)
}
val tailOption: Option[List[T]] = this match {
case Nil() => None[List[T]]()
case Cons(_, t) => Some(t)
}
def head: T = {
require(this != Nil[T]())
val Cons(h, _) = this
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment