on master help sign in
Add splitAt function for List
commite05845224783a396b28ce0bafaa4aec4d2dfaff3 authorJean-Remi Desjardins <jeanremi.desjardins@gmail.com> dateWed 26 Mar 2014, 15:06 (13 years ago) parent577752b
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 : Nat -> 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) =