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

Fix drop example

parent 52dd18ae
No related branches found
No related tags found
No related merge requests found
...@@ -78,14 +78,22 @@ sealed abstract class List[T] { ...@@ -78,14 +78,22 @@ sealed abstract class List[T] {
} }
} }
def drop(i: BigInt): List[T] = (this, i) match { def drop(i: BigInt): List[T] = {
case (Nil(), _) => Nil() require(i >= 0)
case (Cons(h, t), i) => (this, i) match {
if (i == 0) { case (Nil(), _) => Nil[T]()
Cons(h, t) case (Cons(h, t), i) =>
} else { if (i == 0) {
t.drop(i) // FIXME Should be -1 Cons[T](h, t)
} } else {
t.drop(i) // FIXME Should be -1
}
}
} ensuring { (res: List[T]) =>
((this, i), res) passes {
case (Cons(a, Cons(b, Nil())), BigInt(1)) => Cons(b, Nil())
case (Cons(a, Cons(b, Nil())), BigInt(2)) => Nil()
}
} }
def slice(from: BigInt, to: BigInt): List[T] = { def slice(from: BigInt, to: BigInt): List[T] = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment