splitAt -package:ghc

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])
splitAt n xs returns a pair consisting of the prefix of xs of length n and the remaining stream immediately following this prefix.
'splitAt' n xs == ('take' n xs, 'drop' n xs)
xs == ys ++ zs where (ys, zs) = 'splitAt' n xs
O(1) splitAt n xs is equivalent to (take n xs, drop n xs).
O(n/c) splitAt n xs is equivalent to (take n xs, drop n xs).
O(n) splitAt n sbs is equivalent to (take n sbs, drop n sbs). Note: copies the substrings
O(n) splitAt n t returns a pair whose first element is a prefix of t of length n, and whose second is the remainder of the string. It is equivalent to (take n t, drop n t).
O(n) splitAt n t returns a pair whose first element is a prefix of t of length n, and whose second is the remainder of the string. It is equivalent to (take n t, drop n t).
Split a map at a particular index.
splitAt !n !xs = (take n xs, drop n xs)
Split a sequence at a given position. splitAt i s = (take i s, drop i s).
Split a set at a particular index.
splitAt !n !xs = (take n xs, drop n xs)
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.
O(1) Split the mutable vector into the first n elements and the remainder, without copying. Note that splitAt n v is equivalent to (take n v, drop n v), but slightly more efficient.
O(1) Split the mutable vector into the first n elements and 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.
O(1) Split the mutable vector into the first n elements and 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.
O(1) Split the mutable vector into the first n elements and 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.
O(1) Split the mutable vector into the first n elements and the remainder, without copying. Note that splitAt n v is equivalent to (take n v, drop n v), but slightly more efficient.
Split after a given number of characters. Negative values are treated as if they are 0.
Split after a given number of characters. Negative values are treated as if they are 0.
Split after a given number of characters. Negative values are treated as if they are 0.
Split after a given number of characters. Negative values are treated as if they are 0.
Split a bytearray at a specific length in two bytearray