vector-0.3: Efficient Arrays

Portability non-portable experimental Roman Leshchinskiy

Data.Vector

Description

Boxed vectors

Synopsis

# Documentation

data Vector a Source

Instances

 IVector Vector a Eq a => Eq (Vector a) Ord a => Ord (Vector a) Show a => Show (Vector a)

# Construction

Empty vector

singleton :: a -> Vector aSource

Vector with exaclty one element

cons :: a -> Vector a -> Vector aSource

Prepend an element

snoc :: Vector a -> a -> Vector aSource

Append an element

replicate :: Int -> a -> Vector aSource

Vector of the given length with the given value in each position

(++) :: Vector a -> Vector a -> Vector aSource

Concatenate two vectors

copy :: Vector a -> Vector aSource

Create a copy of a vector. Useful when dealing with slices.

# Accessing individual elements

(!) :: Vector a -> Int -> aSource

Indexing

head :: Vector a -> aSource

First element

last :: Vector a -> aSource

Last element

indexM :: Monad m => Vector a -> Int -> m aSource

Monadic indexing which can be strict in the vector while remaining lazy in the element

headM :: Monad m => Vector a -> m aSource

lastM :: Monad m => Vector a -> m aSource

# Subvectors

Arguments

 :: Vector a -> Int starting index -> Int length -> Vector a

Yield a part of the vector without copying it. Safer version of `unsafeSlice`.

init :: Vector a -> Vector aSource

Yield all but the last element without copying.

tail :: Vector a -> Vector aSource

All but the first element (without copying).

take :: Int -> Vector a -> Vector aSource

Yield the first `n` elements without copying.

drop :: Int -> Vector a -> Vector aSource

Yield all but the first `n` elements without copying.

# Permutations

accum :: (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector aSource

(//) :: Vector a -> [(Int, a)] -> Vector aSource

update :: Vector a -> Vector (Int, a) -> Vector aSource

# Mapping

map :: (a -> b) -> Vector a -> Vector bSource

Map a function over a vector

concatMap :: (a -> Vector b) -> Vector a -> Vector bSource

# Zipping and unzipping

zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector cSource

Zip two vectors with the given function.

zipWith3 :: (a -> b -> c -> d) -> Vector a -> Vector b -> Vector c -> Vector dSource

Zip three vectors with the given function.

zip :: Vector a -> Vector b -> Vector (a, b)Source

zip3 :: Vector a -> Vector b -> Vector c -> Vector (a, b, c)Source

unzip :: Vector (a, b) -> (Vector a, Vector b)Source

unzip3 :: Vector (a, b, c) -> (Vector a, Vector b, Vector c)Source

# Filtering

filter :: (a -> Bool) -> Vector a -> Vector aSource

Drop elements which do not satisfy the predicate

takeWhile :: (a -> Bool) -> Vector a -> Vector aSource

Yield the longest prefix of elements satisfying the predicate.

dropWhile :: (a -> Bool) -> Vector a -> Vector aSource

Drop the longest prefix of elements that satisfy the predicate.

# Searching

elem :: Eq a => a -> Vector a -> BoolSource

Check whether the vector contains an element

notElem :: Eq a => a -> Vector a -> BoolSource

Inverse of `elem`

find :: (a -> Bool) -> Vector a -> Maybe aSource

Yield `Just` the first element matching the predicate or `Nothing` if no such element exists.

findIndex :: (a -> Bool) -> Vector a -> Maybe IntSource

Yield `Just` the index of the first element matching the predicate or `Nothing` if no such element exists.

# Folding

foldl :: (a -> b -> a) -> a -> Vector b -> aSource

Left fold

foldl1 :: (a -> a -> a) -> Vector a -> aSource

Lefgt fold on non-empty vectors

foldl' :: (a -> b -> a) -> a -> Vector b -> aSource

Left fold with strict accumulator

foldl1' :: (a -> a -> a) -> Vector a -> aSource

Left fold on non-empty vectors with strict accumulator

foldr :: (a -> b -> b) -> b -> Vector a -> bSource

Right fold

foldr1 :: (a -> a -> a) -> Vector a -> aSource

Right fold on non-empty vectors

# Specialised folds

sum :: Num a => Vector a -> aSource

product :: Num a => Vector a -> aSource

maximum :: Ord a => Vector a -> aSource

minimum :: Ord a => Vector a -> aSource

# Unfolding

unfoldr :: (b -> Maybe (a, b)) -> b -> Vector aSource

# Scans

prescanl :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Prefix scan

prescanl' :: (a -> b -> a) -> a -> Vector b -> Vector aSource

Prefix scan with strict accumulator

# Enumeration

enumFromTo :: Enum a => a -> a -> Vector aSource

enumFromThenTo :: Enum a => a -> a -> a -> Vector aSource

# Conversion to/from lists

toList :: Vector a -> [a]Source

Convert a vector to a list

fromList :: [a] -> Vector aSource

Convert a list to a vector