vector-0.13.1.0: Efficient Arrays
Copyright(c) Roman Leshchinskiy 2008-2010
Alexey Kuleshevich 2020-2022
Aleksey Khudyakov 2020-2022
Andrew Lelechenko 2020-2022
LicenseBSD-style
MaintainerHaskell Libraries Team <libraries@haskell.org>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Vector.Fusion.Bundle.Monadic

Description

Monadic bundles.

Synopsis

Documentation

data Bundle m v a Source #

Monadic streams

Constructors

Bundle 

Fields

Instances

Instances details
Eq1 (Bundle Id v) Source # 
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) Source # 
Instance details

Defined in Data.Vector.Fusion.Bundle

Methods

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

Monad m => Functor (Bundle m v) Source # 
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 #

Eq a => Eq (Bundle Id v a) Source # 
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) Source # 
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 Source #

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 Source #

Convert a pure stream to a monadic stream

Size hints

size :: Bundle m v a -> Size Source #

Size hint of a Bundle

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

Attach a Size hint to a Bundle

Length

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

Length of a Bundle

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

Check if a Bundle is empty

Construction

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

Empty Bundle

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

Singleton Bundle

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

Prepend an element

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

Append an element

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

Replicate a value to a given length

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

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 Source #

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

Generate a stream from its indices

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

Concatenate two Bundles

Accessing elements

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

First element of the Bundle or error if empty

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

Last element of the Bundle or error if empty

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

Element at the given position

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

Element at the given position or Nothing if out of bounds

Substreams

slice Source #

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 Source #

All but the last element

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

All but the first element

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

The first n elements

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

All but the first n elements

Mapping

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

Map a function over a Bundle

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

Map a monadic function over a Bundle

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

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 Source #

Transform a Bundle to use a different monad

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

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

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

Create a Bundle of values from a Bundle of streamable things

Zipping

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

Pair each element in a Bundle with its index

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

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 () Source #

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

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 Source #

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 Source #

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 Source #

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 Source #

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

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

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 Source #

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 Source #

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 Source #

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

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

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) Source #

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) Source #

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) Source #

Comparisons

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

Check if two Bundles are equal

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

Lexicographically compare two Bundles

Filtering

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

Drop elements which do not satisfy the predicate

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

Drop elements which do not satisfy the monadic predicate

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

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 Source #

Longest prefix of elements that satisfy the predicate

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

Longest prefix of elements that satisfy the monadic predicate

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

Drop the longest prefix of elements that satisfy the predicate

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

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 Source #

Check whether the Bundle contains an element

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

Inverse of elem

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

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) Source #

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) Source #

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) Source #

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 Source #

Left fold

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

Left fold with a monadic operator

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

Left fold over a non-empty Bundle

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

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 Source #

Same as foldlM

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

Same as foldl1M

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

Left fold with a strict accumulator

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

Left fold with a strict accumulator and a monadic operator

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

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

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

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 Source #

Same as foldlM'

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

Same as foldl1M'

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

Right fold

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

Right fold with a monadic operator

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

Right fold over a non-empty stream

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

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

Specialised folds

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

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

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

Unfolding

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

Unfold

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

Unfold with a monadic function

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

Unfold at most n elements

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

Unfold at most n elements with a monadic function.

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

Unfold exactly n elements

Since: 0.12.2.0

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

Unfold exactly n elements with a monadic function.

Since: 0.12.2.0

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

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 Source #

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 Source #

Prefix scan

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

Prefix scan with a monadic operator

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

Prefix scan with strict accumulator

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

Prefix scan with strict accumulator and a monadic operator

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

Suffix scan

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

Suffix scan with a monadic operator

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

Suffix scan with strict accumulator

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

Suffix scan with strict accumulator and a monadic operator

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

Haskell-style scan

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

Haskell-style scan with a monadic operator

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

Haskell-style scan with strict accumulator

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

Haskell-style scan with strict accumulator and a monadic operator

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

Initial-value free scan over a Bundle

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

Initial-value free scan over a Bundle with a monadic operator

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

Initial-value free scan over a Bundle with a strict accumulator

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

Initial-value free scan over a Bundle with a strict accumulator and a monadic operator

Enumerations

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

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 Source #

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 Source #

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] Source #

Convert a Bundle to a list

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

Convert a list to a Bundle

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

Convert the first n elements of a list to a Bundle

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

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

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

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

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

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

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

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

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