take is:exact package:base set:included-with-ghc

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]
[]
take n xs returns the first n elements of xs.