:: [a] -> Int -> ([a], [a]) -package:base

splitAtExact n xs =
| n >= 0 && n <= length xs = splitAt n xs
| otherwise                = error "some message"
splitAt n xs returns a tuple where first element is xs prefix of length n and second element is the remainder of the list: splitAt is an instance of the more general genericSplitAt, in which n may be of any integral type.

Laziness

It is equivalent to (take n xs, drop n xs) unless n is _|_: splitAt _|_ xs = _|_, not (_|_, _|_)). The first component of the tuple is produced lazily:
>>> fst (splitAt 0 undefined)
[]
>>> take 1 (fst (splitAt 10 (1 : undefined)))
[1]

Examples

>>> splitAt 6 "Hello World!"
("Hello ","World!")
>>> splitAt 3 [1,2,3,4,5]
([1,2,3],[4,5])
>>> splitAt 1 [1,2,3]
([1],[2,3])
>>> splitAt 3 [1,2,3]
([1,2,3],[])
>>> splitAt 4 [1,2,3]
([1,2,3],[])
>>> splitAt 0 [1,2,3]
([],[1,2,3])
>>> splitAt (-1) [1,2,3]
([],[1,2,3])
splitAtEnd n xs returns a split where the second element tries to contain n elements.
splitAtEnd 3 "hello" == ("he","llo")
splitAtEnd 3 "he"    == ("", "he")
\i xs -> uncurry (++) (splitAt i xs) == xs
\i xs -> splitAtEnd i xs == (dropEnd i xs, takeEnd i xs)
splitAt n xs returns a tuple where first element is xs prefix of length n and second element is the remainder of the list:
>>> splitAt 6 "Hello World!"
("Hello ","World!")

>>> splitAt 3 [1,2,3,4,5]
([1,2,3],[4,5])

>>> splitAt 1 [1,2,3]
([1],[2,3])

>>> splitAt 3 [1,2,3]
([1,2,3],[])

>>> splitAt 4 [1,2,3]
([1,2,3],[])

>>> splitAt 0 [1,2,3]
([],[1,2,3])

>>> splitAt (-1) [1,2,3]
([],[1,2,3])
It is equivalent to (take n xs, drop n xs) when n is not _|_ (splitAt _|_ xs = _|_). splitAt is an instance of the more general genericSplitAt, in which n may be of any integral type.
splitAtRev n xs == (dropRev n xs, takeRev n xs).
\n xs -> splitAtRev n (xs::String) == (dropRev n xs, takeRev n xs)
\n xs -> (xs::String) == uncurry (++) (splitAtRev n xs)
splitAt n xs returns a tuple where first element is xs prefix of length n and second element is the remainder of the list:
splitAt 6 "Hello World!" == ("Hello ","World!")
splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])
splitAt 1 [1,2,3] == ([1],[2,3])
splitAt 3 [1,2,3] == ([1,2,3],[])
splitAt 4 [1,2,3] == ([1,2,3],[])
splitAt 0 [1,2,3] == ([],[1,2,3])
splitAt (-1) [1,2,3] == ([],[1,2,3])
It is equivalent to (take n xs, drop n xs) when n is not _|_ (splitAt _|_ xs = _|_). splitAt is an instance of the more general genericSplitAt, in which n may be of any integral type.
The genericSplitAt function is an overloaded version of splitAt, which accepts any Integral value as the position at which to split.
O(1) Yield the first n elements paired with the remainder, without copying. Note that splitAt n v is equivalent to (take n v, drop n v), but slightly more efficient.
O(1) Yield the first n elements paired with the remainder without copying. Note that splitAt n v is equivalent to (take n v, drop n v) but slightly more efficient.
Split position must be at most the length of the list, otherwise the end of the first list and the second list are undefined.
Split at the given index. Equivalent to (take n xs, drop n xs) and therefore total.
The same as draw, except draw only one hand of specified size.
>>> deck <- evalRandIO $ shuffle $ (fullDeck :: [PlayingCard])

>>> draw1 5 deck
Just ([Six of Clubs,Ace of Hearts,Nine of Hearts,Four of Hearts,Two of Diamonds],[King of Diamonds,Queen of Spades,Four of Spades,Seven of Hearts,Five of Hearts,Seven of Clubs,Three of Hearts,Ace of Spades,Three of Diamonds,Seven of Diamonds,Two of Clubs,Five of Spades,King of Hearts,Jack of Hearts,Queen of Hearts,Ten of Clubs,Five of Clubs,Eight of Spades,Ace of Clubs,King of Clubs,Five of Diamonds,Queen of Diamonds,Eight of Hearts,Four of Clubs,Three of Clubs,Jack of Clubs,Jack of Diamonds,Ten of Diamonds,Queen of Clubs,Eight of Diamonds,Six of Diamonds,Eight of Clubs,Three of Spades,Two of Hearts,Six of Spades,King of Spades,Ten of Hearts,Nine of Spades,Nine of Diamonds,Two of Spades,Ten of Spades,Nine of Clubs,Four of Diamonds,Ace of Diamonds,Six of Hearts,Seven of Spades,Jack of Spades])