diff --git a/library/collection/List.scala b/library/collection/List.scala index b3078c600d7e00430ea4100633ad9feacd1022cd..d9031e8b7dc494e691a405cd9c32aa9e2439fbef 100644 --- a/library/collection/List.scala +++ b/library/collection/List.scala @@ -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