Skip to content
Snippets Groups Projects
Commit ac667904 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Add List.init

parent d8e4551a
No related branches found
No related tags found
No related merge requests found
......@@ -185,6 +185,15 @@ sealed abstract class List[T] {
}
}
def init: List[T] = (this match {
case Cons(h, Nil()) =>
Nil[T]()
case Cons(h, t) =>
Cons[T](h, t.init)
case Nil() =>
Nil[T]()
}) ensuring ( (r: List[T]) => ((r.size < this.size) || (this.size == 0)) )
def lastOption: Option[T] = this match {
case Cons(h, t) =>
t.lastOption.orElse(Some(h))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment