:: Int -> [a] -> [a] package:ghc-lib-parser
take n, applied to a list
xs, returns the
prefix of
xs of length
n, or
xs itself if
n >= length xs.
It is an instance of the more general
genericTake, in which
n may be of any integral type.
Laziness
>>> take 0 undefined
[]
>>> take 2 (1 : 2 : undefined)
[1,2]
Examples
>>> take 5 "Hello World!"
"Hello"
>>> take 3 [1,2,3,4,5]
[1,2,3]
>>> take 3 [1,2]
[1,2]
>>> take 3 []
[]
>>> take (-1) [1,2]
[]
>>> take 0 [1,2]
[]
drop n xs returns the suffix of
xs after the
first
n elements, or
[] if
n >= length
xs.
It is an instance of the more general
genericDrop, in which
n may be of any integral type.
Examples
>>> drop 6 "Hello World!"
"World!"
>>> drop 3 [1,2,3,4,5]
[4,5]
>>> drop 3 [1,2]
[]
>>> drop 3 []
[]
>>> drop (-1) [1,2]
[1,2]
>>> drop 0 [1,2]
[1,2]
drop from the end of a list