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

tailOption in List

parent 419597e3
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,12 @@ sealed abstract class List[T] { ...@@ -40,6 +40,12 @@ sealed abstract class List[T] {
case Cons(h, _) => Some(h) 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 = { def head: T = {
require(this != Nil[T]()) require(this != Nil[T]())
val Cons(h, _) = this 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