:: [a] -> Int -> [a] -package:safe

O(1) Indexing in a monad. The monad allows operations to be strict in the vector when necessary. Suppose vector copying is implemented like this:
copy mv v = ... write mv i (v ! i) ...
For lazy vectors, v ! i would not be evaluated which means that mv would unnecessarily retain a reference to v in each element written. With indexM, copying can be implemented like this instead:
copy mv v = ... do
x <- indexM v i
write mv i x
Here, no references to v are retained because indexing (but not the element) is evaluated eagerly.
O(1) Indexing in a monad, without bounds checks. See indexM for an explanation of why this is useful.
A (!!) that fails using mzero
Raise a polynomial to a non-negative integer power
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
Drop a number of elements from the end of the list.
dropEnd 3 "hello"  == "he"
dropEnd 5 "bye"    == ""
dropEnd (-1) "bye" == "bye"
\i xs -> dropEnd i xs `isPrefixOf` xs
\i xs -> length (dropEnd i xs) == max 0 (length xs - max 0 i)
\i -> take 3 (dropEnd 5 [i..]) == take 3 [i..]
Take a number of elements from the end of the list.
takeEnd 3 "hello"  == "llo"
takeEnd 5 "bye"    == "bye"
takeEnd (-1) "bye" == ""
\i xs -> takeEnd i xs `isSuffixOf` xs
\i xs -> length (takeEnd i xs) == min (max 0 i) (length xs)
drop n xs returns the suffix of xs after the first n elements, or [] if n >= length xs.
>>> 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]
It is an instance of the more general genericDrop, in which n may be of any integral type.
take n, applied to a list xs, returns the prefix of xs of length n, or xs itself if n >= length xs.
>>> 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]
[]
It is an instance of the more general genericTake, in which n may be of any integral type.
dropRev n is like reverse . drop n . reverse but it is lazy enough to work for infinite lists, too.
\n xs -> dropRev n (xs::String) == reverse (drop n (reverse xs))
takeRev n is like reverse . take n . reverse but it is lazy enough to work for infinite lists, too.
\n xs -> takeRev n (xs::String) == reverse (take n (reverse xs))
keep every k-th value from the list
>>> sieve 6 ['a'..'z']
"agmsy"
rotate left
drop n xs returns the suffix of xs after the first n elements, or [] if n > length xs:
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]
It is an instance of the more general genericDrop, in which n may be of any integral type.
take n, applied to a list xs, returns the prefix of xs of length n, or xs itself if n > length xs:
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] == []
It is an instance of the more general genericTake, in which n may be of any integral type.
Shuffle a list given a seed for an RNG
Take elements from the end of a list.