mirror of
https://github.com/Kindelia/Kind2.git
synced 2024-10-26 16:20:40 +03:00
14 lines
440 B
Plaintext
14 lines
440 B
Plaintext
// # Take n elements of a list and return the rest of the list as a pair.
|
|
// - List.split([1, 2, 3], 2) == ([1, 2], [3])
|
|
// - List.split(xs, n) == (List.take(xs, n), List.drop(xs, n))
|
|
|
|
List.split<A: Type>(xs : List<A>, n : Nat) : Pair<List<A>, List<A>>
|
|
case n {
|
|
zero : {[], xs}
|
|
succ : case xs {
|
|
nil : {[], xs}
|
|
cons :
|
|
let {xs, ys} = List.split(A, xs.tail, n.pred)
|
|
{List.cons(A, xs.head, xs), ys}
|
|
}
|
|
} |