From ac667904cc7b8becbe151d0c1f639318b937ff31 Mon Sep 17 00:00:00 2001
From: Etienne Kneuss <colder@php.net>
Date: Mon, 18 Aug 2014 17:11:45 +0200
Subject: [PATCH] Add List.init

---
 library/collection/List.scala | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/library/collection/List.scala b/library/collection/List.scala
index 5720d635f..b94f4fd2e 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))
-- 
GitLab