rio-0.1.21.0: A standard library for Haskell

RIO.Vector.Boxed

Description

Boxed Vector. Import as:

import qualified RIO.Vector.Boxed as VB

This module does not export any partial or unsafe functions. For those, see RIO.Vector.Boxed.Partial and RIO.Vector.Boxed.Unsafe

Synopsis

Boxed vectors

data Vector a #

Boxed vectors, supporting efficient slicing.

Instances

Instances details
True
False
>>> V.any even $V.fromList [3, 2, 13 :: Int] True >>> V.any even (V.empty :: V.Vector Int) False O(n) Check if all elements are True Examples Expand >>> import qualified Data.Vector as V >>> V.and$ V.fromList [True, False]
False
>>> V.and V.empty
True

O(n) Check if any element is True

Examples

Expand
>>> import qualified Data.Vector as V
>>> V.or $V.fromList [True, False] True >>> V.or V.empty False sum :: Num a => Vector a -> a # O(n) Compute the sum of the elements Examples Expand >>> import qualified Data.Vector as V >>> V.sum$ V.fromList [300,20,1 :: Int]
321
>>> V.sum (V.empty :: V.Vector Int)
0

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

O(n) Compute the produce of the elements

Examples

Expand
>>> import qualified Data.Vector as V
>>> V.product \$ V.fromList [1,2,3,4 :: Int]
24
>>> V.product (V.empty :: V.Vector Int)
1

foldM :: Monad m => (a -> b -> m a) -> a -> Vector b -> m a #

ifoldM :: Monad m => (a -> Int -> b -> m a) -> a -> Vector b -> m a #

O(n) Monadic fold (action applied to each element and its index)

foldM' :: Monad m => (a -> b -> m a) -> a -> Vector b -> m a #

O(n) Monadic fold with strict accumulator

ifoldM' :: Monad m => (a -> Int -> b -> m a) -> a -> Vector b -> m a #

O(n) Monadic fold with strict accumulator (action applied to each element and its index)

foldM_ :: Monad m => (a -> b -> m a) -> a -> Vector b -> m () #

ifoldM_ :: Monad m => (a -> Int -> b -> m a) -> a -> Vector b -> m () #

O(n) Monadic fold that discards the result (action applied to each element and its index)

foldM'_ :: Monad m => (a -> b -> m a) -> a -> Vector b -> m () #

ifoldM'_ :: Monad m => (a -> Int -> b -> m a) -> a -> Vector b -> m () #

O(n) Monadic fold with strict accumulator that discards the result (action applied to each element and its index)

sequence :: Monad m => Vector (m a) -> m (Vector a) #

Evaluate each action and collect the results

sequence_ :: Monad m => Vector (m a) -> m () #

Evaluate each action and discard the results

Prefix sums (scans)

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

O(n) Prescan

prescanl f z = init . scanl f z

Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6>

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

O(n) Prescan with strict accumulator

postscanl :: (a -> b -> a) -> a -> Vector b -> Vector a #

O(n) Scan

postscanl f z = tail . scanl f z

Example: postscanl (+) 0 <1,2,3,4> = <1,3,6,10>

postscanl' :: (a -> b -> a) -> a -> Vector b -> Vector a #

O(n) Scan with strict accumulator

scanl :: (a -> b -> a) -> a -> Vector b -> Vector a #

scanl f z <x1,...,xn> = <y1,...,y(n+1)>
where y1 = z
yi = f y(i-1) x(i-1)

Example: scanl (+) 0 <1,2,3,4> = <0,1,3,6,10>

scanl' :: (a -> b -> a) -> a -> Vector b -> Vector a #

O(n) Haskell-style scan with strict accumulator

iscanl :: (Int -> a -> b -> a) -> a -> Vector b -> Vector a #

O(n) Scan over a vector with its index

Since: vector-0.12.0.0

iscanl' :: (Int -> a -> b -> a) -> a -> Vector b -> Vector a #

O(n) Scan over a vector (strictly) with its index

Since: vector-0.12.0.0

prescanr :: (a -> b -> b) -> b -> Vector a -> Vector b #

O(n) Right-to-left prescan

prescanr f z = reverse . prescanl (flip f) z . reverse

prescanr' :: (a -> b -> b) -> b -> Vector a -> Vector b #

O(n) Right-to-left prescan with strict accumulator

postscanr :: (a -> b -> b) -> b -> Vector a -> Vector b #

O(n) Right-to-left scan

postscanr' :: (a -> b -> b) -> b -> Vector a -> Vector b #

O(n) Right-to-left scan with strict accumulator

scanr :: (a -> b -> b) -> b -> Vector a -> Vector b #

scanr' :: (a -> b -> b) -> b -> Vector a -> Vector b #

O(n) Right-to-left Haskell-style scan with strict accumulator

iscanr :: (Int -> a -> b -> b) -> b -> Vector a -> Vector b #

O(n) Right-to-left scan over a vector with its index

Since: vector-0.12.0.0

iscanr' :: (Int -> a -> b -> b) -> b -> Vector a -> Vector b #

O(n) Right-to-left scan over a vector (strictly) with its index

Since: vector-0.12.0.0

Conversions

Lists

toList :: Vector a -> [a] #

O(n) Convert a vector to a list

fromList :: [a] -> Vector a #

O(n) Convert a list to a vector

fromListN :: Int -> [a] -> Vector a #

O(n) Convert the first n elements of a list to a vector

fromListN n xs = fromList (take n xs)

Different vector types

convert :: (Vector v a, Vector w a) => v a -> w a #

O(n) Convert different vector types

Mutable vectors

freeze :: PrimMonad m => MVector (PrimState m) a -> m (Vector a) #

O(n) Yield an immutable copy of the mutable vector.

thaw :: PrimMonad m => Vector a -> m (MVector (PrimState m) a) #

O(n) Yield a mutable copy of the immutable vector.

copy :: PrimMonad m => MVector (PrimState m) a -> Vector a -> m () #

O(n) Copy an immutable vector into a mutable one. The two vectors must have the same length.