vector-0.12.3.0: Efficient Arrays
Copyright(c) Roman Leshchinskiy 2008-2010
LicenseBSD-style
MaintainerRoman Leshchinskiy <rl@cse.unsw.edu.au>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Vector.Fusion.Bundle.Monadic

Description

Monadic bundles.

Synopsis

Documentation

data Bundle m v a #

Monadic streams

Constructors

Bundle 

Fields

Instances

Instances details
Monad m => Functor (Bundle m v) # 
Instance details

Defined in Data.Vector.Fusion.Bundle.Monadic

Methods

fmap :: (a -> b) -> Bundle m v a -> Bundle m v b #

(<$) :: a -> Bundle m v b -> Bundle m v a #

Eq1 (Bundle Id v) # 
Instance details

Defined in Data.Vector.Fusion.Bundle

Methods

liftEq :: (a -> b -> Bool) -> Bundle Id v a -> Bundle Id v b -> Bool #

Ord1 (Bundle Id v) # 
Instance details

Defined in Data.Vector.Fusion.Bundle

Methods

liftCompare :: (a -> b -> Ordering) -> Bundle Id v a -> Bundle Id v b -> Ordering #

Eq a => Eq (Bundle Id v a) # 
Instance details

Defined in Data.Vector.Fusion.Bundle

Methods

(==) :: Bundle Id v a -> Bundle Id v a -> Bool #

(/=) :: Bundle Id v a -> Bundle Id v a -> Bool #

Ord a => Ord (Bundle Id v a) # 
Instance details

Defined in Data.Vector.Fusion.Bundle

Methods

compare :: Bundle Id v a -> Bundle Id v a -> Ordering #

(<) :: Bundle Id v a -> Bundle Id v a -> Bool #

(<=) :: Bundle Id v a -> Bundle Id v a -> Bool #

(>) :: Bundle Id v a -> Bundle Id v a -> Bool #

(>=) :: Bundle Id v a -> Bundle Id v a -> Bool #

max :: Bundle Id v a -> Bundle Id v a -> Bundle Id v a #

min :: Bundle Id v a -> Bundle Id v a -> Bundle Id v a #

data Chunk v a #

Constructors

Chunk Int (forall m. (PrimMonad m, Vector v a) => Mutable v (PrimState m) a -> m ()) 

lift :: Monad m => Bundle Id v a -> Bundle m v a #

Convert a pure stream to a monadic stream

Size hints

size :: Bundle m v a -> Size #

Size hint of a Bundle

sized :: Bundle m v a -> Size -> Bundle m v a #

Attach a Size hint to a Bundle

Length

length :: Monad m => Bundle m v a -> m Int #

Length of a Bundle

null :: Monad m => Bundle m v a -> m Bool #

Check if a Bundle is empty

Construction

empty :: Monad m => Bundle m v a #

Empty Bundle

singleton :: Monad m => a -> Bundle m v a #

Singleton Bundle

cons :: Monad m => a -> Bundle m v a -> Bundle m v a #

Prepend an element

snoc :: Monad m => Bundle m v a -> a -> Bundle m v a #

Append an element

replicate :: Monad m => Int -> a -> Bundle m v a #

Replicate a value to a given length

replicateM :: Monad m => Int -> m a -> Bundle m v a #

Yield a Bundle of values obtained by performing the monadic action the given number of times

generate :: Monad m => Int -> (Int -> a) -> Bundle m v a #

generateM :: Monad m => Int -> (Int -> m a) -> Bundle m v a #

Generate a stream from its indices

(++) :: Monad m => Bundle m v a -> Bundle m v a -> Bundle m v a infixr 5 #

Concatenate two Bundles

Accessing elements

head :: Monad m => Bundle m v a -> m a #

First element of the Bundle or error if empty

last :: Monad m => Bundle m v a -> m a #

Last element of the Bundle or error if empty

(!!) :: Monad m => Bundle m v a -> Int -> m a infixl 9 #

Element at the given position

(!?) :: Monad m => Bundle m v a -> Int -> m (Maybe a) infixl 9 #

Element at the given position or Nothing if out of bounds

Substreams

slice #

Arguments

:: Monad m 
=> Int

starting index

-> Int

length

-> Bundle m v a 
-> Bundle m v a 

Extract a substream of the given length starting at the given position.

init :: Monad m => Bundle m v a -> Bundle m v a #

All but the last element

tail :: Monad m => Bundle m v a -> Bundle m v a #

All but the first element

take :: Monad m => Int -> Bundle m v a -> Bundle m v a #

The first n elements

drop :: Monad m => Int -> Bundle m v a -> Bundle m v a #

All but the first n elements

Mapping

map :: Monad m => (a -> b) -> Bundle m v a -> Bundle m v b #

Map a function over a Bundle

mapM :: Monad m => (a -> m b) -> Bundle m v a -> Bundle m v b #

Map a monadic function over a Bundle

mapM_ :: Monad m => (a -> m b) -> Bundle m v a -> m () #

Execute a monadic action for each element of the Bundle

trans :: (Monad m, Monad m') => (forall z. m z -> m' z) -> Bundle m v a -> Bundle m' v a #

Transform a Bundle to use a different monad

unbox :: Monad m => Bundle m v (Box a) -> Bundle m v a #

concatMap :: Monad m => (a -> Bundle m v b) -> Bundle m v a -> Bundle m v b #

flatten :: Monad m => (a -> m s) -> (s -> m (Step s b)) -> Size -> Bundle m v a -> Bundle m v b #

Create a Bundle of values from a Bundle of streamable things

Zipping

indexed :: Monad m => Bundle m v a -> Bundle m v (Int, a) #

Pair each element in a Bundle with its index

indexedR :: Monad m => Int -> Bundle m v a -> Bundle m v (Int, a) #

Pair each element in a Bundle with its index, starting from the right and counting down

zipWithM_ :: Monad m => (a -> b -> m c) -> Bundle m v a -> Bundle m v b -> m () #

zipWithM :: Monad m => (a -> b -> m c) -> Bundle m v a -> Bundle m v b -> Bundle m v c #

Zip two Bundles with the given monadic function

zipWith3M :: Monad m => (a -> b -> c -> m d) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d #

zipWith4M :: Monad m => (a -> b -> c -> d -> m e) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e #

zipWith5M :: Monad m => (a -> b -> c -> d -> e -> m f) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e -> Bundle m v f #

zipWith6M :: Monad m => (a -> b -> c -> d -> e -> f -> m g) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e -> Bundle m v f -> Bundle m v g #

zipWith :: Monad m => (a -> b -> c) -> Bundle m v a -> Bundle m v b -> Bundle m v c #

zipWith3 :: Monad m => (a -> b -> c -> d) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d #

zipWith4 :: Monad m => (a -> b -> c -> d -> e) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e #

zipWith5 :: Monad m => (a -> b -> c -> d -> e -> f) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e -> Bundle m v f #

zipWith6 :: Monad m => (a -> b -> c -> d -> e -> f -> g) -> Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e -> Bundle m v f -> Bundle m v g #

zip :: Monad m => Bundle m v a -> Bundle m v b -> Bundle m v (a, b) #

zip3 :: Monad m => Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v (a, b, c) #

zip4 :: Monad m => Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v (a, b, c, d) #

zip5 :: Monad m => Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e -> Bundle m v (a, b, c, d, e) #

zip6 :: Monad m => Bundle m v a -> Bundle m v b -> Bundle m v c -> Bundle m v d -> Bundle m v e -> Bundle m v f -> Bundle m v (a, b, c, d, e, f) #

Comparisons

eqBy :: Monad m => (a -> b -> Bool) -> Bundle m v a -> Bundle m v b -> m Bool #

Check if two Bundles are equal

cmpBy :: Monad m => (a -> b -> Ordering) -> Bundle m v a -> Bundle m v b -> m Ordering #

Lexicographically compare two Bundles

Filtering

filter :: Monad m => (a -> Bool) -> Bundle m v a -> Bundle m v a #

Drop elements which do not satisfy the predicate

filterM :: Monad m => (a -> m Bool) -> Bundle m v a -> Bundle m v a #

Drop elements which do not satisfy the monadic predicate

mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Bundle m v a -> Bundle m v b #

Apply monadic function to each element and drop all Nothings

Since: 0.12.2.0

takeWhile :: Monad m => (a -> Bool) -> Bundle m v a -> Bundle m v a #

Longest prefix of elements that satisfy the predicate

takeWhileM :: Monad m => (a -> m Bool) -> Bundle m v a -> Bundle m v a #

Longest prefix of elements that satisfy the monadic predicate

dropWhile :: Monad m => (a -> Bool) -> Bundle m v a -> Bundle m v a #

Drop the longest prefix of elements that satisfy the predicate

dropWhileM :: Monad m => (a -> m Bool) -> Bundle m v a -> Bundle m v a #

Drop the longest prefix of elements that satisfy the monadic predicate

Searching

elem :: (Monad m, Eq a) => a -> Bundle m v a -> m Bool infix 4 #

Check whether the Bundle contains an element

notElem :: (Monad m, Eq a) => a -> Bundle m v a -> m Bool infix 4 #

Inverse of elem

find :: Monad m => (a -> Bool) -> Bundle m v a -> m (Maybe a) #

Yield Just the first element that satisfies the predicate or Nothing if no such element exists.

findM :: Monad m => (a -> m Bool) -> Bundle m v a -> m (Maybe a) #

Yield Just the first element that satisfies the monadic predicate or Nothing if no such element exists.

findIndex :: Monad m => (a -> Bool) -> Bundle m v a -> m (Maybe Int) #

Yield Just the index of the first element that satisfies the predicate or Nothing if no such element exists.

findIndexM :: Monad m => (a -> m Bool) -> Bundle m v a -> m (Maybe Int) #

Yield Just the index of the first element that satisfies the monadic predicate or Nothing if no such element exists.

Folding

foldl :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> m a #

Left fold

foldlM :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> m a #

Left fold with a monadic operator

foldl1 :: Monad m => (a -> a -> a) -> Bundle m v a -> m a #

Left fold over a non-empty Bundle

foldl1M :: Monad m => (a -> a -> m a) -> Bundle m v a -> m a #

Left fold over a non-empty Bundle with a monadic operator

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

Same as foldlM

fold1M :: Monad m => (a -> a -> m a) -> Bundle m v a -> m a #

Same as foldl1M

foldl' :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> m a #

Left fold with a strict accumulator

foldlM' :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> m a #

Left fold with a strict accumulator and a monadic operator

foldl1' :: Monad m => (a -> a -> a) -> Bundle m v a -> m a #

Left fold over a non-empty Bundle with a strict accumulator

foldl1M' :: Monad m => (a -> a -> m a) -> Bundle m v a -> m a #

Left fold over a non-empty Bundle with a strict accumulator and a monadic operator

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

Same as foldlM'

fold1M' :: Monad m => (a -> a -> m a) -> Bundle m v a -> m a #

Same as foldl1M'

foldr :: Monad m => (a -> b -> b) -> b -> Bundle m v a -> m b #

Right fold

foldrM :: Monad m => (a -> b -> m b) -> b -> Bundle m v a -> m b #

Right fold with a monadic operator

foldr1 :: Monad m => (a -> a -> a) -> Bundle m v a -> m a #

Right fold over a non-empty stream

foldr1M :: Monad m => (a -> a -> m a) -> Bundle m v a -> m a #

Right fold over a non-empty stream with a monadic operator

Specialised folds

and :: Monad m => Bundle m v Bool -> m Bool #

or :: Monad m => Bundle m v Bool -> m Bool #

concatMapM :: Monad m => (a -> m (Bundle m v b)) -> Bundle m v a -> Bundle m v b #

Unfolding

unfoldr :: Monad m => (s -> Maybe (a, s)) -> s -> Bundle m u a #

Unfold

unfoldrM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Bundle m u a #

Unfold with a monadic function

unfoldrN :: Monad m => Int -> (s -> Maybe (a, s)) -> s -> Bundle m u a #

Unfold at most n elements

unfoldrNM :: Monad m => Int -> (s -> m (Maybe (a, s))) -> s -> Bundle m u a #

Unfold at most n elements with a monadic function.

unfoldrExactN :: Monad m => Int -> (s -> (a, s)) -> s -> Bundle m u a #

Unfold exactly n elements

Since: 0.12.2.0

unfoldrExactNM :: Monad m => Int -> (s -> m (a, s)) -> s -> Bundle m u a #

Unfold exactly n elements with a monadic function.

Since: 0.12.2.0

iterateN :: Monad m => Int -> (a -> a) -> a -> Bundle m u a #

O(n) Apply function \(\max(n - 1, 0)\) times to an initial value, producing a monadic bundle of exact length \(\max(n, 0)\). Zeroth element will contain the initial value.

iterateNM :: Monad m => Int -> (a -> m a) -> a -> Bundle m u a #

O(n) Apply monadic function \(\max(n - 1, 0)\) times to an initial value, producing a monadic bundle of exact length \(\max(n, 0)\). Zeroth element will contain the initial value.

Scans

prescanl :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> Bundle m v a #

Prefix scan

prescanlM :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> Bundle m v a #

Prefix scan with a monadic operator

prescanl' :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> Bundle m v a #

Prefix scan with strict accumulator

prescanlM' :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> Bundle m v a #

Prefix scan with strict accumulator and a monadic operator

postscanl :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> Bundle m v a #

Suffix scan

postscanlM :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> Bundle m v a #

Suffix scan with a monadic operator

postscanl' :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> Bundle m v a #

Suffix scan with strict accumulator

postscanlM' :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> Bundle m v a #

Suffix scan with strict acccumulator and a monadic operator

scanl :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> Bundle m v a #

Haskell-style scan

scanlM :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> Bundle m v a #

Haskell-style scan with a monadic operator

scanl' :: Monad m => (a -> b -> a) -> a -> Bundle m v b -> Bundle m v a #

Haskell-style scan with strict accumulator

scanlM' :: Monad m => (a -> b -> m a) -> a -> Bundle m v b -> Bundle m v a #

Haskell-style scan with strict accumulator and a monadic operator

scanl1 :: Monad m => (a -> a -> a) -> Bundle m v a -> Bundle m v a #

Scan over a non-empty Bundle

scanl1M :: Monad m => (a -> a -> m a) -> Bundle m v a -> Bundle m v a #

Scan over a non-empty Bundle with a monadic operator

scanl1' :: Monad m => (a -> a -> a) -> Bundle m v a -> Bundle m v a #

Scan over a non-empty Bundle with a strict accumulator

scanl1M' :: Monad m => (a -> a -> m a) -> Bundle m v a -> Bundle m v a #

Scan over a non-empty Bundle with a strict accumulator and a monadic operator

Enumerations

enumFromStepN :: (Num a, Monad m) => a -> a -> Int -> Bundle m v a #

Yield a Bundle of the given length containing the values x, x+y, x+y+y etc.

enumFromTo :: (Enum a, Monad m) => a -> a -> Bundle m v a #

Enumerate values

WARNING: This operation can be very inefficient. If at all possible, use enumFromStepN instead.

enumFromThenTo :: (Enum a, Monad m) => a -> a -> a -> Bundle m v a #

Enumerate values with a given step.

WARNING: This operation is very inefficient. If at all possible, use enumFromStepN instead.

Conversions

toList :: Monad m => Bundle m v a -> m [a] #

Convert a Bundle to a list

fromList :: Monad m => [a] -> Bundle m v a #

Convert a list to a Bundle

fromListN :: Monad m => Int -> [a] -> Bundle m v a #

Convert the first n elements of a list to a Bundle

unsafeFromList :: Monad m => Size -> [a] -> Bundle m v a #

Convert a list to a Bundle with the given Size hint.

fromVector :: (Monad m, Vector v a) => v a -> Bundle m v a #

reVector :: Monad m => Bundle m u a -> Bundle m v a #

fromVectors :: forall m v a. (Monad m, Vector v a) => [v a] -> Bundle m v a #

concatVectors :: (Monad m, Vector v a) => Bundle m u (v a) -> Bundle m v a #

fromStream :: Monad m => Stream m a -> Size -> Bundle m v a #

chunks :: Bundle m v a -> Stream m (Chunk v a) #

elements :: Bundle m v a -> Stream m a #