diff --git a/library/collection/List.scala b/library/collection/List.scala index 5720d635f8b22b5e59ab545746f79af4d0bb3f88..b94f4fd2ef464234010ea11f8003c513e5c083dc 100644 --- a/library/collection/List.scala +++ b/library/collection/List.scala @@ -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))