on master help sign in
Merge pull request #1009 from jedesah/list_splitAt

Add splitAt function for List

commit8f5e40f0bacca48168e4b46c150bd6c7f67b0c0b authorEdwin Brady <edwin.brady@gmail.com> dateTue 1 Apr 2014, 14:10 (13 years ago) parentd763c9c06fbec1
1 file changed+8
libs/prelude/Prelude/List.idr+8
libs/prelude/Prelude/List.idr+8
@@ -422,6 +422,14 @@ split p xs =
422422 (chunk, []) => [chunk]
423423 (chunk, (c :: rest)) => chunk :: split p (assert_smaller xs rest)
424424
425+||| A tuple where the first element is a List of the n first elements and
426+||| the second element is a List of the remaining elements of the list
427+||| It is equivalent to (take n xs, drop n xs)
428+||| @ n the index to split at
429+||| @ xs the list to split in two
430+splitAt : (n : Nat) -> (xs : List a) -> (List a, List a)
431+splitAt n xs = (take n xs, drop n xs)
432+
425433partition : (a -> Bool) -> List a -> (List a, List a)
426434partition p [] = ([], [])
427435partition p (x::xs) =