vector-stream-0.1.0.1: Efficient Streams

Copyright | (c) Roman Leshchinskiy 2008-2010 Alexey Kuleshevich 2020-2022 Aleksey Khudyakov 2020-2022 Andrew Lelechenko 2020-2022
License | BSD-style
Maintainer | Haskell Libraries Team <libraries@haskell.org>
Stability | experimental
Portability | non-portable
Safe Haskell | None
Language | Haskell2010

Data.Stream.Monadic

Contents

- Box monad
- Stream
  - Length
  - Construction
  - Accessing elements
  - Substreams
  - Mapping
  - Zipping
  - Comparisons
  - Filtering
  - Searching
  - Folding
  - Specialised folds
  - Unfolding
  - Scans
  - Enumerations
  - Conversions

Description

Monadic stream combinators.

Synopsis

- data Box a = Box {
  - unBox :: a
  }
- liftBox :: Monad m => Box a -> m a
- data Stream (m :: Type -> Type) a = Stream (s -> m (Step s a)) s
- data Step s a where
  - Yield :: forall a s. a -> s -> Step s a
  - Skip :: forall s a. s -> Step s a
  - Done :: forall s a. Step s a
- data SPEC
  - = SPEC
  - | SPEC2
- length :: Monad m => Stream m a -> m Int
- null :: Monad m => Stream m a -> m Bool
- empty :: forall (m :: Type -> Type) a. Monad m => Stream m a
- singleton :: forall (m :: Type -> Type) a. Monad m => a -> Stream m a
- cons :: forall (m :: Type -> Type) a. Monad m => a -> Stream m a -> Stream m a
- snoc :: forall (m :: Type -> Type) a. Monad m => Stream m a -> a -> Stream m a
- replicate :: forall (m :: Type -> Type) a. Monad m => Int -> a -> Stream m a
- replicateM :: Monad m => Int -> m a -> Stream 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
- (++) :: forall (m :: Type -> Type) a. Monad m => Stream m a -> Stream m a -> Stream m a
- head :: (HasCallStack, Monad m) => Stream m a -> m a
- last :: (HasCallStack, Monad m) => Stream m a -> m a
- (!!) :: (HasCallStack, Monad m) => Stream m a -> Int -> m a
- (!?) :: Monad m => Stream m a -> Int -> m (Maybe a)
- slice :: forall (m :: Type -> Type) a. Monad m => Int -> Int -> Stream m a -> Stream m a
- init :: forall (m :: Type -> Type) a. (HasCallStack, Monad m) => Stream m a -> Stream m a
- tail :: forall (m :: Type -> Type) a. (HasCallStack, Monad m) => Stream m a -> Stream m a
- take :: forall (m :: Type -> Type) a. Monad m => Int -> Stream m a -> Stream m a
- drop :: forall (m :: Type -> Type) a. Monad m => Int -> Stream m a -> Stream m a
- map :: forall (m :: Type -> Type) a b. Monad m => (a -> b) -> Stream m a -> Stream m b
- mapM :: Monad m => (a -> m b) -> Stream m a -> Stream m b
- mapM_ :: Monad m => (a -> m b) -> Stream m a -> m ()
- trans :: (Monad m, Monad m') => (forall z. m z -> m' z) -> Stream m a -> Stream m' a
- unbox :: forall (m :: Type -> Type) a. Monad m => Stream m (Box a) -> Stream m a
- concatMap :: forall (m :: Type -> Type) a b. Monad m => (a -> Stream m b) -> Stream m a -> Stream m b
- flatten :: Monad m => (a -> m s) -> (s -> m (Step s b)) -> Stream m a -> Stream m b
- indexed :: forall (m :: Type -> Type) a. Monad m => Stream m a -> Stream m (Int, a)
- indexedR :: forall (m :: Type -> Type) a. Monad m => Int -> Stream m a -> Stream m (Int, a)
- zipWithM_ :: Monad m => (a -> b -> m c) -> Stream m a -> Stream m b -> m ()
- zipWithM :: Monad m => (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
- 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
- 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
- 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
- zip :: forall (m :: Type -> Type) a b. Monad m => Stream m a -> Stream m b -> Stream m (a, b)
- zip3 :: forall (m :: Type -> Type) a b c. Monad m => Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
- 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)
- eqBy :: Monad m => (a -> b -> Bool) -> Stream m a -> Stream m b -> m Bool
- cmpBy :: Monad m => (a -> b -> Ordering) -> Stream m a -> Stream m b -> m Ordering
- filter :: forall (m :: Type -> Type) a. Monad m => (a -> Bool) -> Stream m a -> Stream m a
- filterM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
- uniq :: forall a (m :: Type -> Type). (Eq a, Monad m) => Stream m a -> Stream m a
- mapMaybe :: forall (m :: Type -> Type) a b. Monad m => (a -> Maybe b) -> Stream m a -> Stream m b
- mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Stream m a -> Stream m b
- catMaybes :: forall (m :: Type -> Type) a. Monad m => Stream m (Maybe a) -> Stream m a
- takeWhile :: forall (m :: Type -> Type) a. Monad m => (a -> Bool) -> Stream m a -> Stream m a
- takeWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
- dropWhile :: forall (m :: Type -> Type) a. Monad m => (a -> Bool) -> Stream m a -> Stream m a
- dropWhileM :: Monad m => (a -> m Bool) -> Stream m a -> Stream m a
- elem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
- notElem :: (Monad m, Eq a) => a -> Stream m a -> m Bool
- find :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe a)
- findM :: Monad m => (a -> m Bool) -> Stream m a -> m (Maybe a)
- findIndex :: Monad m => (a -> Bool) -> Stream m a -> m (Maybe Int)
- findIndexM :: Monad m => (a -> m Bool) -> Stream m a -> m (Maybe Int)
- foldl :: Monad m => (a -> b -> a) -> a -> Stream m b -> m a
- foldlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
- foldl1 :: Monad m => (a -> a -> a) -> Stream m a -> m a
- foldl1M :: (HasCallStack, Monad m) => (a -> a -> m a) -> Stream m a -> m a
- foldM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
- fold1M :: Monad m => (a -> a -> m a) -> Stream m a -> m a
- foldl' :: Monad m => (a -> b -> a) -> a -> Stream m b -> m a
- foldlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
- foldl1' :: Monad m => (a -> a -> a) -> Stream m a -> m a
- foldl1M' :: (HasCallStack, Monad m) => (a -> a -> m a) -> Stream m a -> m a
- foldM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> m a
- fold1M' :: Monad m => (a -> a -> m a) -> Stream m a -> m a
- foldr :: Monad m => (a -> b -> b) -> b -> Stream m a -> m b
- foldrM :: Monad m => (a -> b -> m b) -> b -> Stream m a -> m b
- foldr1 :: Monad m => (a -> a -> a) -> Stream m a -> m a
- foldr1M :: (HasCallStack, Monad m) => (a -> a -> m a) -> Stream m a -> m a
- and :: Monad m => Stream m Bool -> m Bool
- or :: Monad m => Stream m Bool -> m Bool
- concatMapM :: Monad m => (a -> m (Stream m b)) -> Stream m a -> Stream m b
- unfoldr :: forall (m :: Type -> Type) s a. Monad m => (s -> Maybe (a, s)) -> s -> Stream m a
- unfoldrM :: Monad m => (s -> m (Maybe (a, s))) -> s -> Stream m a
- unfoldrN :: forall (m :: Type -> Type) s a. Monad m => Int -> (s -> Maybe (a, s)) -> s -> Stream m a
- unfoldrNM :: Monad m => Int -> (s -> m (Maybe (a, s))) -> s -> Stream m a
- unfoldrExactN :: forall (m :: Type -> Type) s a. Monad m => Int -> (s -> (a, s)) -> s -> Stream m a
- unfoldrExactNM :: Monad m => Int -> (s -> m (a, s)) -> s -> Stream m a
- iterateN :: forall (m :: Type -> Type) a. Monad m => Int -> (a -> a) -> a -> Stream m a
- iterateNM :: Monad m => Int -> (a -> m a) -> a -> Stream m a
- prescanl :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- prescanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- prescanl' :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- prescanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- postscanl :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- postscanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- postscanl' :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- postscanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- scanl :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- scanlM :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- scanl' :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> a) -> a -> Stream m b -> Stream m a
- scanlM' :: Monad m => (a -> b -> m a) -> a -> Stream m b -> Stream m a
- scanl1 :: forall (m :: Type -> Type) a. Monad m => (a -> a -> a) -> Stream m a -> Stream m a
- scanl1M :: Monad m => (a -> a -> m a) -> Stream m a -> Stream m a
- scanl1' :: forall (m :: Type -> Type) a. Monad m => (a -> a -> a) -> Stream m a -> Stream m a
- scanl1M' :: Monad m => (a -> a -> m a) -> Stream m a -> Stream m a
- enumFromStepN :: forall a (m :: Type -> Type). (Num a, Monad m) => a -> a -> Int -> Stream m a
- enumFromTo :: forall a (m :: Type -> Type). (Enum a, Monad m) => a -> a -> Stream m a
- enumFromThenTo :: forall a (m :: Type -> Type). (Enum a, Monad m) => a -> a -> a -> Stream m a
- toList :: Monad m => Stream m a -> m [a]
- fromList :: forall (m :: Type -> Type) a. Monad m => [a] -> Stream m a
- fromListN :: forall (m :: Type -> Type) a. Monad m => Int -> [a] -> Stream m a

# Box monad

data Box a Source #

Box monad

Constructors

Box |

Fields

- unBox :: a

#### Instances

Instances details

Applicative Box Source # |
Instance details Defined in Data.Stream.Monadic Methods pure :: a -> Box a Source # (<*>) :: Box (a -> b) -> Box a -> Box b Source # liftA2 :: (a -> b -> c) -> Box a -> Box b -> Box c Source # (*>) :: Box a -> Box b -> Box b Source # (<*) :: Box a -> Box b -> Box a Source #
Functor Box Source # |
Instance details Defined in Data.Stream.Monadic Methods fmap :: (a -> b) -> Box a -> Box b Source # (<$) :: a -> Box b -> Box a Source #
Monad Box Source # |
Instance details Defined in Data.Stream.Monadic Methods (>>=) :: Box a -> (a -> Box b) -> Box b Source # (>>) :: Box a -> Box b -> Box b Source # return :: a -> Box a Source #

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

# Stream

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

Monadic streams

Constructors

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

#### Instances

Instances details

Monad m => Functor (Stream m) Source # |
Instance details Defined in Data.Stream.Monadic Methods fmap :: (a -> b) -> Stream m a -> Stream m b Source # (<$) :: a -> Stream m b -> Stream m a Source #

data Step s a where Source #

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) Source # |
Instance details Defined in Data.Stream.Monadic Methods fmap :: (a -> b) -> Step s a -> Step s b Source # (<$) :: a -> Step s b -> Step s a Source #

data SPEC Source #

`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 constructors 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 |

## Length

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

Length of a `Stream`

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

Check if a `Stream` is empty

## Construction

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

Empty `Stream`

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

Singleton `Stream`

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

Prepend an element

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

Append an element

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

Replicate a value to a given length

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

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

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

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

Generate a stream from its indices

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

Concatenate two `Stream`s

## Accessing elements

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

First element of the `Stream` or error if empty

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

Last element of the `Stream` or error if empty

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

Element at the given position

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

Element at the given position or `Nothing` if out of bounds

## Substreams

slice Source #

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.

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

All but the last element

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

All but the first element

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

The first `n` elements

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

All but the first `n` elements

## Mapping

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

Map a function over a `Stream`

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

Map a monadic function over a `Stream`

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

Execute a monadic action for each element of the `Stream`

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

Transform a `Stream` to use a different monad

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

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

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

Create a `Stream` of values from a `Stream` of streamable things

## Zipping

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

Pair each element in a `Stream` with its index

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

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

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

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

Zip two `Stream`s with the given monadic function

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

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

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

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

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

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

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

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

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

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

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

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

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

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

## Comparisons

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

Check if two `Stream`s are equal

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

Lexicographically compare two `Stream`s

## Filtering

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

Drop elements which do not satisfy the predicate

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

Drop elements which do not satisfy the monadic predicate

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

Drop repeated adjacent elements.

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

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

Apply monadic function to each element and drop all Nothings

Since: 0.12.2.0

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

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

Longest prefix of elements that satisfy the predicate

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

Longest prefix of elements that satisfy the monadic predicate

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

Drop the longest prefix of elements that satisfy the predicate

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

Drop the longest prefix of elements that satisfy the monadic predicate

## Searching

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

Check whether the `Stream` contains an element

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

Inverse of `elem`

find :: Monad m => (a -> Bool) -> Stream m 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) -> Stream m 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) -> Stream m 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) -> Stream m 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 -> Stream m b -> m a Source #

Left fold

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

Left fold with a monadic operator

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

Left fold over a non-empty `Stream`

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

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

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

Same as `foldlM`

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

Same as `foldl1M`

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

Left fold with a strict accumulator

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

Left fold with a strict accumulator and a monadic operator

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

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

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

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

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

Same as `foldlM'`

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

Same as `foldl1M'`

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

Right fold

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

Right fold with a monadic operator

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

Right fold over a non-empty stream

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

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

## Specialised folds

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

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

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

## Unfolding

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

Unfold

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

Unfold with a monadic function

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

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

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

Unfold exactly `n` elements

Since: 0.12.2.0

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

Unfold exactly `n` elements with a monadic function.

Since: 0.12.2.0

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

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

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

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

## Scans

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

Prefix scan

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

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

Prefix scan with strict accumulator

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

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

Suffix scan

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

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

Suffix scan with strict accumulator

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

Suffix scan with strict acccumulator and a monadic operator

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

Haskell-style scan

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

Haskell-style scan with a monadic operator

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

Haskell-style scan with strict accumulator

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

Haskell-style scan with strict accumulator and a monadic operator

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

Initial-value free scan over a `Stream`

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

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

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

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

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

## Enumerations

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

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

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

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

Enumerate values with a given step.

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

## Conversions

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

Convert a `Stream` to a list

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

Convert a list to a `Stream`

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

Convert the first `n` elements of a list to a `Bundle`