From 2e198dcf81b87c3ef02440306b03fa9af60b5c3b Mon Sep 17 00:00:00 2001 From: Manos Koukoutos <emmanouil.koukoutos@epfl.ch> Date: Wed, 2 Sep 2015 18:44:35 +0200 Subject: [PATCH] List.tailOption in lib --- library/collection/List.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/collection/List.scala b/library/collection/List.scala index 0fc2d4f84..e75b588c7 100644 --- a/library/collection/List.scala +++ b/library/collection/List.scala @@ -266,6 +266,14 @@ sealed abstract class List[T] { None[T]() }} ensuring { _.isDefined != this.isEmpty } + def tailOption: Option[List[T]] = { this match { + case Cons(h, t) => + Some(t) + case Nil() => + None[List[T]]() + }} ensuring { _.isDefined != this.isEmpty } + + def unique: List[T] = this match { case Nil() => Nil() case Cons(h, t) => -- GitLab