splitAt

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)
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.
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.
Split a bytearray at a specific length in two bytearray
Split a bytearray at a specific length in two bytearray
\(Shape xs) (List ys) -> Match.splitAt xs ys == (Match.take xs ys, Match.drop xs ys)
\(Shape xs) (List ys) -> Match.splitAt xs ys == List.splitAt (length xs) ys
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) 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]
splitAt is an instance of the more general genericSplitAt, in which n may be of any integral type.
Split a succession of layers after some number, returning a streaming or effectful pair. This function is the same as the splitsAt exported by the Streaming module, but since this module is imported qualified, it can usurp a Prelude name. It specializes to:
splitAt :: (Monad m) => Int -> Stream (Of a) m r -> Stream (Of a) m (Stream (Of a) m r)
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.
O(log n). Split a map at a particular index.
splitAt !n !xs = (take n xs, drop n xs)
O(log n). 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.