rebase-1.21.2: A more progressive alternative to the "base" package
Safe HaskellNone
LanguageHaskell2010

Rebase.Data.Vector.Fusion.Stream.Monadic

Synopsis

Documentation

data Stream (m :: Type -> Type) a #

Monadic streams

Constructors

Stream (s -> m (Step s a)) s 

Instances

Instances details
Monad m => Functor (Stream m) 
Instance details

Defined in Data.Stream.Monadic

Methods

fmap :: (a -> b) -> Stream m a -> Stream m b #

(<$) :: a -> Stream m b -> Stream m a #

indexed :: forall (m :: Type -> Type) a. Monad m => Stream m a -> Stream m (Int, a) #

Pair each element in a Stream with its index

data Box a #

Box monad

Constructors

Box 

Fields

Instances

Instances details
Applicative Box 
Instance details

Defined in Data.Stream.Monadic

Methods

pure :: a -> Box a #

(<*>) :: Box (a -> b) -> Box a -> Box b #

liftA2 :: (a -> b -> c) -> Box a -> Box b -> Box c #

(*>) :: Box a -> Box b -> Box b #

(<*) :: Box a -> Box b -> Box a #

Functor Box 
Instance details

Defined in Data.Stream.Monadic

Methods

fmap :: (a -> b) -> Box a -> Box b #

(<$) :: a -> Box b -> Box a #

Monad Box 
Instance details

Defined in Data.Stream.Monadic

Methods

(>>=) :: Box a -> (a -> Box b) -> Box b #

(>>) :: Box a -> Box b -> Box b #

return :: a -> Box a #

(++) :: forall (m :: Type -> Type) a. Monad m => Stream m a -> Stream m a -> Stream m a infixr 5 #

Concatenate two Streams

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

Right fold

map :: forall (m :: Type -> Type) a b. Monad m => (a -> b) -> Stream m a -> Stream m b #

Map a function over a Stream

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

Element at the given position or Nothing if out of bounds

data SPEC #

SPEC is used by GHC in the SpecConstr pass in order to inform the compiler when to be particularly aggressive. In particular, it tells GHC to specialize regardless of size or the number of specializations. However, not all loops fall into this category.

Libraries can specify this by using SPEC data type to inform which loops should be aggressively specialized. For example, instead of

loop x where loop arg = ...

write

loop SPEC x where loop !_ arg = ...

There is no semantic difference between SPEC and SPEC2, we just need a type with two contructors lest it is optimised away before SpecConstr.

This type is reexported from GHC.Exts since GHC 9.0 and base-4.15. For compatibility with earlier releases import it from GHC.Types in ghc-prim package.

Since: ghc-prim-0.3.1.0

Constructors

SPEC 
SPEC2 

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

Left fold

mapMaybe :: forall (m :: Type -> Type) a b. Monad m => (a -> Maybe b) -> Stream m a -> Stream m b #

length :: Monad m => Stream m a -> m Int #

Length of a Stream

head :: (HasCallStack, Monad m) => Stream m a -> m a #

First element of the Stream or error if empty

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

Left fold with a strict accumulator

foldl1 :: Monad m => (a -> a -> a) -> Stream m a -> m a #

Left fold over a non-empty Stream

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

Map a monadic function over a Stream

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

Execute a monadic action for each element of the Stream

filter :: forall (m :: Type -> Type) a. Monad m => (a -> Bool) -> Stream m a -> Stream m a #

Drop elements which do not satisfy the predicate

unfoldr :: forall (m :: Type -> Type) s a. Monad m => (s -> Maybe (a, s)) -> s -> Stream m a #

Unfold

zip :: forall (m :: Type -> Type) a b. Monad m => Stream m a -> Stream m b -> Stream m (a, b) #

enumFromTo :: forall a (m :: Type -> Type). (Enum a, Monad m) => a -> a -> Stream m a #

Enumerate values

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

enumFromThenTo :: forall a (m :: Type -> Type). (Enum a, Monad m) => a -> a -> a -> Stream m a #

Enumerate values with a given step.

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

fromList :: forall (m :: Type -> Type) a. Monad m => [a] -> Stream m a #

Convert a list to a Stream

fromListN :: forall (m :: Type -> Type) a. Monad m => Int -> [a] -> Stream m a #

Convert the first n elements of a list to a Bundle

toList :: Monad m => Stream m a -> m [a] #

Convert a Stream to a list

empty :: forall (m :: Type -> Type) a. Monad m => Stream m a #

Empty Stream

catMaybes :: forall (m :: Type -> Type) a. Monad m => Stream m (Maybe a) -> Stream m a #

tail :: forall (m :: Type -> Type) a. (HasCallStack, Monad m) => Stream m a -> Stream m a #

All but the first element

last :: (HasCallStack, Monad m) => Stream m a -> m a #

Last element of the Stream or error if empty

init :: forall (m :: Type -> Type) a. (HasCallStack, Monad m) => Stream m a -> Stream m a #

All but the last element

null :: Monad m => Stream m a -> m Bool #

Check if a Stream is empty

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

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

scanl :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a #

Haskell-style scan

scanl1 :: forall (m :: Type -> Type) a. Monad m => (a -> a -> a) -> Stream m a -> Stream m a #

Initial-value free scan over a Stream

scanl' :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a #

Haskell-style scan with strict accumulator

foldr1 :: Monad m => (a -> a -> a) -> Stream m a -> m a #

Right fold over a non-empty stream

replicate :: forall (m :: Type -> Type) a. Monad m => Int -> a -> Stream m a #

Replicate a value to a given length

takeWhile :: forall (m :: Type -> Type) a. Monad m => (a -> Bool) -> Stream m a -> Stream m a #

Longest prefix of elements that satisfy the predicate

dropWhile :: forall (m :: Type -> Type) a. Monad m => (a -> Bool) -> Stream m a -> Stream m a #

Drop the longest prefix of elements that satisfy the predicate

take :: forall (m :: Type -> Type) a. Monad m => Int -> Stream m a -> Stream m a #

The first n elements

drop :: forall (m :: Type -> Type) a. Monad m => Int -> Stream m a -> Stream m a #

All but the first n elements

and :: Monad m => Stream m Bool -> m Bool #

or :: Monad m => Stream m Bool -> m Bool #

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

Check whether the Stream contains an element

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

Inverse of elem

concatMap :: forall (m :: Type -> Type) a b. Monad m => (a -> Stream m b) -> Stream m a -> Stream m b #

(!!) :: (HasCallStack, Monad m) => Stream m a -> Int -> m a infixl 9 #

Element at the given position

zip3 :: forall (m :: Type -> Type) a b c. Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c) #

zipWith :: forall (m :: Type -> Type) a b c. Monad m => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c #

zipWith3 :: forall (m :: Type -> Type) a b c d. Monad m => (a -> b -> c -> d) -> Stream m a -> Stream m b -> Stream m c -> Stream m d #

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

Transform a Stream to use a different monad

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

Right fold with a monadic operator

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

Left fold with a monadic operator

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

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

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

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

zip4 :: forall (m :: Type -> Type) a b c d. Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m (a, b, c, d) #

zip5 :: forall (m :: Type -> Type) a b c d e. Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m e -> Stream m (a, b, c, d, e) #

zip6 :: forall (m :: Type -> Type) a b c d e f. Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m e -> Stream m f -> Stream m (a, b, c, d, e, f) #

zipWith4 :: forall (m :: Type -> Type) a b c d e. Monad m => (a -> b -> c -> d -> e) -> Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m e #

zipWith5 :: forall (m :: Type -> Type) a b c d e f. Monad m => (a -> b -> c -> d -> e -> f) -> Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m e -> Stream m f #

zipWith6 :: forall (m :: Type -> Type) a b c d e f g. Monad m => (a -> b -> c -> d -> e -> f -> g) -> Stream m a -> Stream m b -> Stream m c -> Stream m d -> Stream m e -> Stream m f -> Stream m g #

singleton :: forall (m :: Type -> Type) a. Monad m => a -> Stream m a #

Singleton Stream

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

Drop elements which do not satisfy the monadic predicate

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

Zip two Streams with the given monadic function

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

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

Same as foldlM

replicateM :: Monad m => Int -> m a -> Stream m a #

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

cons :: forall (m :: Type -> Type) a. Monad m => a -> Stream m a -> Stream m a #

Prepend an element

snoc :: forall (m :: Type -> Type) a. Monad m => Stream m a -> a -> Stream m a #

Append an element

data Step s a where #

Result of taking a single step in a stream

Constructors

Yield :: forall a s. a -> s -> Step s a 
Skip :: forall s a. s -> Step s a 
Done :: forall s a. Step s a 

Instances

Instances details
Functor (Step s) 
Instance details

Defined in Data.Stream.Monadic

Methods

fmap :: (a -> b) -> Step s a -> Step s b #

(<$) :: a -> Step s b -> Step s a #

unfoldrN :: forall (m :: Type -> Type) s a. Monad m => Int -> (s -> Maybe (a, s)) -> s -> Stream m a #

iterateN :: forall (m :: Type -> Type) a. Monad m => Int -> (a -> a) -> a -> Stream m a #

O(n) Apply function \(\max(n - 1, 0)\) times to an initial value, producing a stream of \(\max(n, 0)\) values.

flatten :: Monad m => (a -> m s) -> (s -> m (Step s b)) -> Stream m a -> Stream m b #

Create a Stream of values from a Stream of streamable things

liftBox :: Monad m => Box a -> m a #

generate :: forall (m :: Type -> Type) a. Monad m => Int -> (Int -> a) -> Stream m a #

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

Generate a stream from its indices

slice #

Arguments

:: forall (m :: Type -> Type) a. Monad m 
=> Int

starting index

-> Int

length

-> Stream m a 
-> Stream m a 

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

unbox :: forall (m :: Type -> Type) a. Monad m => Stream m (Box a) -> Stream m a #

indexedR :: forall (m :: Type -> Type) a. Monad m => Int -> Stream m a -> Stream m (Int, a) #

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

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

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

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

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

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

Check if two Streams are equal

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

Lexicographically compare two Streams

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

Apply monadic function to each element and drop all Nothings

Since: vector-stream-0.12.2.0

uniq :: forall a (m :: Type -> Type). (Eq a, Monad m) => Stream m a -> Stream m a #

Drop repeated adjacent elements.

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

Longest prefix of elements that satisfy the monadic predicate

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

Drop the longest prefix of elements that satisfy the monadic predicate

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

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

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

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

foldl1M :: (HasCallStack, Monad m) => (a -> a -> m a) -> Stream m a -> m a #

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

fold1M :: Monad m => (a -> a -> m a) -> Stream m a -> m a #

Same as foldl1M

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

Left fold with a strict accumulator and a monadic operator

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

Same as foldlM'

foldl1M' :: (HasCallStack, Monad m) => (a -> a -> m a) -> Stream m a -> m a #

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

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

Same as foldl1M'

foldr1M :: (HasCallStack, Monad m) => (a -> a -> m a) -> Stream m a -> m a #

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

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

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

Unfold with a monadic function

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

Unfold at most n elements with a monadic function.

unfoldrExactN :: forall (m :: Type -> Type) s a. Monad m => Int -> (s -> (a, s)) -> s -> Stream m a #

Unfold exactly n elements

Since: vector-stream-0.12.2.0

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

Unfold exactly n elements with a monadic function.

Since: vector-stream-0.12.2.0

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

O(n) Apply monadic function \(\max(n - 1, 0)\) times to an initial value, producing a stream of \(\max(n, 0)\) values.

prescanl :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a #

Prefix scan

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

Prefix scan with a monadic operator

prescanl' :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a #

Prefix scan with strict accumulator

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

Prefix scan with strict accumulator and a monadic operator

postscanl :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a #

Suffix scan

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

Suffix scan with a monadic operator

postscanl' :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a #

Suffix scan with strict accumulator

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

Suffix scan with strict acccumulator and a monadic operator

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

Haskell-style scan with a monadic operator

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

Haskell-style scan with strict accumulator and a monadic operator

scanl1M :: Monad m => (a -> a -> m a) -> Stream m a -> Stream m a #

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

scanl1' :: forall (m :: Type -> Type) a. Monad m => (a -> a -> a) -> Stream m a -> Stream m a #

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

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

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

enumFromStepN :: forall a (m :: Type -> Type). (Num a, Monad m) => a -> a -> Int -> Stream m a #

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