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] {
}
}
def drop(i: BigInt): List[T] = (this, i) match {
case (Nil(), _) => Nil()
case (Cons(h, t), i) =>
if (i == 0) {
Cons(h, t)
} else {
t.drop(i) // FIXME Should be -1
}
def drop(i: BigInt): List[T] = {
require(i >= 0)
(this, i) match {
case (Nil(), _) => Nil[T]()
case (Cons(h, t), i) =>
if (i == 0) {
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] = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment