Data.Conduit.List

conduit-1.3.6: Streaming data processing library.

Safe Haskell | Trustworthy
Language | Haskell2010

Data.Conduit.List

Contents

- Sources
- Sinks
  - Pure
  - Monadic
- Conduits
  - Pure
  - Monadic
- Misc

Description

NOTE It is recommended to start using Data.Conduit.Combinators instead of this module.

Higher-level functions to interact with the elements of a stream. Most of these are based on list functions.

Note that these functions all deal with individual elements of a stream as a sort of "black box", where there is no introspection of the contained elements. Values such as `ByteString` and `Text` will likely need to be treated specially to deal with their contents properly (`Word8` and `Char`, respectively). See the `Data.Conduit.Binary` and `Data.Conduit.Text` modules in the `conduit-extra` package.

Synopsis

- sourceList :: forall (m :: Type -> Type) a i. Monad m => [a] -> ConduitT i a m ()
- sourceNull :: forall (m :: Type -> Type) i o. Monad m => ConduitT i o m ()
- unfold :: forall (m :: Type -> Type) b a i. Monad m => (b -> Maybe (a, b)) -> b -> ConduitT i a m ()
- unfoldEither :: forall (m :: Type -> Type) b r a i. Monad m => (b -> Either r (a, b)) -> b -> ConduitT i a m r
- unfoldM :: Monad m => (b -> m (Maybe (a, b))) -> b -> ConduitT i a m ()
- unfoldEitherM :: Monad m => (b -> m (Either r (a, b))) -> b -> ConduitT i a m r
- enumFromTo :: forall a (m :: Type -> Type) i. (Enum a, Ord a, Monad m) => a -> a -> ConduitT i a m ()
- iterate :: forall (m :: Type -> Type) a i. Monad m => (a -> a) -> a -> ConduitT i a m ()
- replicate :: forall (m :: Type -> Type) a i. Monad m => Int -> a -> ConduitT i a m ()
- replicateM :: Monad m => Int -> m a -> ConduitT i a m ()
- fold :: forall (m :: Type -> Type) b a o. Monad m => (b -> a -> b) -> b -> ConduitT a o m b
- foldMap :: forall (m :: Type -> Type) b a o. (Monad m, Monoid b) => (a -> b) -> ConduitT a o m b
- uncons :: SealedConduitT () o Identity () -> Maybe (o, SealedConduitT () o Identity ())
- unconsEither :: SealedConduitT () o Identity r -> Either r (o, SealedConduitT () o Identity r)
- take :: forall (m :: Type -> Type) a o. Monad m => Int -> ConduitT a o m [a]
- drop :: forall (m :: Type -> Type) a o. Monad m => Int -> ConduitT a o m ()
- head :: forall (m :: Type -> Type) a o. Monad m => ConduitT a o m (Maybe a)
- peek :: forall (m :: Type -> Type) a o. Monad m => ConduitT a o m (Maybe a)
- consume :: forall (m :: Type -> Type) a o. Monad m => ConduitT a o m [a]
- sinkNull :: forall (m :: Type -> Type) i o. Monad m => ConduitT i o m ()
- foldMapM :: (Monad m, Monoid b) => (a -> m b) -> ConduitT a o m b
- foldM :: Monad m => (b -> a -> m b) -> b -> ConduitT a o m b
- unconsM :: Monad m => SealedConduitT () o m () -> m (Maybe (o, SealedConduitT () o m ()))
- unconsEitherM :: Monad m => SealedConduitT () o m r -> m (Either r (o, SealedConduitT () o m r))
- mapM_ :: Monad m => (a -> m ()) -> ConduitT a o m ()
- map :: forall (m :: Type -> Type) a b. Monad m => (a -> b) -> ConduitT a b m ()
- mapMaybe :: forall (m :: Type -> Type) a b. Monad m => (a -> Maybe b) -> ConduitT a b m ()
- mapFoldable :: forall (m :: Type -> Type) f a b. (Monad m, Foldable f) => (a -> f b) -> ConduitT a b m ()
- catMaybes :: forall (m :: Type -> Type) a. Monad m => ConduitT (Maybe a) a m ()
- concat :: forall (m :: Type -> Type) f a. (Monad m, Foldable f) => ConduitT (f a) a m ()
- concatMap :: forall (m :: Type -> Type) a b. Monad m => (a -> [b]) -> ConduitT a b m ()
- concatMapAccum :: forall (m :: Type -> Type) a accum b. Monad m => (a -> accum -> (accum, [b])) -> accum -> ConduitT a b m ()
- scanl :: forall (m :: Type -> Type) a s b. Monad m => (a -> s -> (s, b)) -> s -> ConduitT a b m ()
- scan :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> b) -> b -> ConduitT a b m b
- mapAccum :: forall (m :: Type -> Type) a s b. Monad m => (a -> s -> (s, b)) -> s -> ConduitT a b m s
- chunksOf :: forall (m :: Type -> Type) a. Monad m => Int -> ConduitT a [a] m ()
- groupBy :: forall (m :: Type -> Type) a. Monad m => (a -> a -> Bool) -> ConduitT a [a] m ()
- groupOn1 :: forall (m :: Type -> Type) b a. (Monad m, Eq b) => (a -> b) -> ConduitT a (a, [a]) m ()
- groupOn :: forall (m :: Type -> Type) b a. (Monad m, Eq b) => (a -> b) -> ConduitT a (NonEmpty a) m ()
- isolate :: forall (m :: Type -> Type) a. Monad m => Int -> ConduitT a a m ()
- filter :: forall (m :: Type -> Type) a. Monad m => (a -> Bool) -> ConduitT a a m ()
- mapM :: Monad m => (a -> m b) -> ConduitT a b m ()
- iterM :: Monad m => (a -> m ()) -> ConduitT a a m ()
- scanlM :: Monad m => (a -> s -> m (s, b)) -> s -> ConduitT a b m ()
- scanM :: Monad m => (a -> b -> m b) -> b -> ConduitT a b m b
- mapAccumM :: Monad m => (a -> s -> m (s, b)) -> s -> ConduitT a b m s
- mapMaybeM :: Monad m => (a -> m (Maybe b)) -> ConduitT a b m ()
- mapFoldableM :: (Monad m, Foldable f) => (a -> m (f b)) -> ConduitT a b m ()
- concatMapM :: Monad m => (a -> m [b]) -> ConduitT a b m ()
- concatMapAccumM :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> ConduitT a b m ()
- sequence :: forall (m :: Type -> Type) i o. Monad m => ConduitT i o m o -> ConduitT i o m ()

# Sources

sourceList :: forall (m :: Type -> Type) a i. Monad m => [a] -> ConduitT i a m () #

Yield the values from the list.

Subject to fusion

sourceNull :: forall (m :: Type -> Type) i o. Monad m => ConduitT i o m () #

A source that outputs no values. Note that this is just a type-restricted synonym for `mempty`.

Subject to fusion

Since 0.3.0

unfold :: forall (m :: Type -> Type) b a i. Monad m => (b -> Maybe (a, b)) -> b -> ConduitT i a m () #

Generate a source from a seed value.

Subject to fusion

Since 0.4.2

unfoldEither :: forall (m :: Type -> Type) b r a i. Monad m => (b -> Either r (a, b)) -> b -> ConduitT i a m r #

Generate a source from a seed value with a return value.

Subject to fusion

Since: 1.2.11

unfoldM :: Monad m => (b -> m (Maybe (a, b))) -> b -> ConduitT i a m () #

A monadic unfold.

Subject to fusion

Since 1.1.2

unfoldEitherM :: Monad m => (b -> m (Either r (a, b))) -> b -> ConduitT i a m r #

A monadic unfoldEither.

Subject to fusion

Since: 1.2.11

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

Enumerate from a value to a final value, inclusive, via `succ`.

This is generally more efficient than using `Prelude`'s `enumFromTo` and combining with `sourceList` since this avoids any intermediate data structures.

Subject to fusion

Since 0.4.2

iterate :: forall (m :: Type -> Type) a i. Monad m => (a -> a) -> a -> ConduitT i a m () #

Produces an infinite stream of repeated applications of f to x.

Subject to fusion

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

Replicate a single value the given number of times.

Subject to fusion

Since 1.2.0

replicateM :: Monad m => Int -> m a -> ConduitT i a m () #

Replicate a monadic value the given number of times.

Subject to fusion

Since 1.2.0

# Sinks

## Pure

fold :: forall (m :: Type -> Type) b a o. Monad m => (b -> a -> b) -> b -> ConduitT a o m b #

A strict left fold.

Subject to fusion

Since 0.3.0

foldMap :: forall (m :: Type -> Type) b a o. (Monad m, Monoid b) => (a -> b) -> ConduitT a o m b #

A monoidal strict left fold.

Subject to fusion

Since 0.5.3

uncons :: SealedConduitT () o Identity () -> Maybe (o, SealedConduitT () o Identity ()) #

Split a pure conduit into head and tail. This is equivalent to `runIdentity . unconsM`.

Note that you have to `sealConduitT` it first.

Since 1.3.3

unconsEither :: SealedConduitT () o Identity r -> Either r (o, SealedConduitT () o Identity r) #

Split a pure conduit into head and tail or return its result if it is done. This is equivalent to `runIdentity . unconsEitherM`.

Note that you have to `sealConduitT` it first.

Since 1.3.3

take :: forall (m :: Type -> Type) a o. Monad m => Int -> ConduitT a o m [a] #

Take some values from the stream and return as a list. If you want to instead create a conduit that pipes data to another sink, see `isolate`. This function is semantically equivalent to:

    take i = isolate i =$ consume

Subject to fusion

Since 0.3.0

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

Ignore a certain number of values in the stream. This function is semantically equivalent to:

    drop i = take i >> return ()

However, `drop` is more efficient as it does not need to hold values in memory.

Subject to fusion

Since 0.3.0

head :: forall (m :: Type -> Type) a o. Monad m => ConduitT a o m (Maybe a) #

Take a single value from the stream, if available.

Subject to fusion

Since 0.3.0

peek :: forall (m :: Type -> Type) a o. Monad m => ConduitT a o m (Maybe a) #

Look at the next value in the stream, if available. This function will not change the state of the stream.

Since 0.3.0

consume :: forall (m :: Type -> Type) a o. Monad m => ConduitT a o m [a] #

Consume all values from the stream and return as a list. Note that this will pull all values into memory.

Subject to fusion

Since 0.3.0

sinkNull :: forall (m :: Type -> Type) i o. Monad m => ConduitT i o m () #

Ignore the remainder of values in the source. Particularly useful when combined with `isolate`.

Subject to fusion

Since 0.3.0

## Monadic

foldMapM :: (Monad m, Monoid b) => (a -> m b) -> ConduitT a o m b #

A monoidal strict left fold in a Monad.

Since 1.0.8

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

A monadic strict left fold.

Subject to fusion

Since 0.3.0

unconsM :: Monad m => SealedConduitT () o m () -> m (Maybe (o, SealedConduitT () o m ())) #

Split a conduit into head and tail.

Note that you have to `sealConduitT` it first.

Since 1.3.3

unconsEitherM :: Monad m => SealedConduitT () o m r -> m (Either r (o, SealedConduitT () o m r)) #

Split a conduit into head and tail or return its result if it is done.

Note that you have to `sealConduitT` it first.

Since 1.3.3

mapM_ :: Monad m => (a -> m ()) -> ConduitT a o m () #

Apply the action to all values in the stream.

Subject to fusion

Since 0.3.0

# Conduits

## Pure

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

Apply a transformation to all values in a stream.

Subject to fusion

Since 0.3.0

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

Apply a transformation that may fail to all values in a stream, discarding the failures.

Subject to fusion

Since 0.5.1

mapFoldable :: forall (m :: Type -> Type) f a b. (Monad m, Foldable f) => (a -> f b) -> ConduitT a b m () #

Generalization of `mapMaybe` and `concatMap`. It applies function to all values in a stream and send values inside resulting `Foldable` downstream.

Subject to fusion

Since 1.0.6

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

Filter the `Just` values from a stream, discarding the `Nothing` values.

Subject to fusion

Since 0.5.1

concat :: forall (m :: Type -> Type) f a. (Monad m, Foldable f) => ConduitT (f a) a m () #

Generalization of `catMaybes`. It puts all values from `Foldable` into stream.

Subject to fusion

Since 1.0.6

concatMap :: forall (m :: Type -> Type) a b. Monad m => (a -> [b]) -> ConduitT a b m () #

Apply a transformation to all values in a stream, concatenating the output values.

Subject to fusion

Since 0.3.0

concatMapAccum :: forall (m :: Type -> Type) a accum b. Monad m => (a -> accum -> (accum, [b])) -> accum -> ConduitT a b m () #

`concatMap` with a strict accumulator.

Subject to fusion

Since 0.3.0

scanl :: forall (m :: Type -> Type) a s b. Monad m => (a -> s -> (s, b)) -> s -> ConduitT a b m () #

Deprecated: Use mapAccum instead

Deprecated synonym for `mapAccum`

Since 1.0.6

scan :: forall (m :: Type -> Type) a b. Monad m => (a -> b -> b) -> b -> ConduitT a b m b #

Analog of `scanl` for lists.

Subject to fusion

Since 1.1.1

mapAccum :: forall (m :: Type -> Type) a s b. Monad m => (a -> s -> (s, b)) -> s -> ConduitT a b m s #

Analog of `mapAccumL` for lists. Note that in contrast to `mapAccumL`, the function argument takes the accumulator as its second argument, not its first argument, and the accumulated value is strict.

Subject to fusion

Since 1.1.1

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

Group a stream into chunks of a given size. The last chunk may contain fewer than n elements.

Subject to fusion

Since 1.2.9

groupBy :: forall (m :: Type -> Type) a. Monad m => (a -> a -> Bool) -> ConduitT a [a] m () #

Grouping input according to an equality function.

Subject to fusion

Since 0.3.0

groupOn1 :: forall (m :: Type -> Type) b a. (Monad m, Eq b) => (a -> b) -> ConduitT a (a, [a]) m () #

`groupOn1` is similar to `groupBy id`

returns a pair, indicating there are always 1 or more items in the grouping. This is designed to be converted into a NonEmpty structure but it avoids a dependency on another package

    import Data.List.NonEmpty

    groupOn1 :: (Monad m, Eq b) => (a -> b) -> Conduit a m (NonEmpty a)
    groupOn1 f = CL.groupOn1 f .| CL.map (uncurry (:|))

Subject to fusion

Since 1.1.7

groupOn :: forall (m :: Type -> Type) b a. (Monad m, Eq b) => (a -> b) -> ConduitT a (NonEmpty a) m () #

Like `groupOn1`, but returning a `NonEmpty` structure.

Since: 1.3.5

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

Ensure that the inner sink consumes no more than the given number of values. Note this this does not ensure that the sink consumes all of those values. To get the latter behavior, combine with `sinkNull`, e.g.:

    src $$ do
        x <- isolate count =$ do
            x <- someSink
            sinkNull
            return x
        someOtherSink
        ...

Subject to fusion

Since 0.3.0

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

Keep only values in the stream passing a given predicate.

Subject to fusion

Since 0.3.0

## Monadic

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

Apply a monadic transformation to all values in a stream.

If you do not need the transformed values, and instead just want the monadic side-effects of running the action, see `mapM_`.

Subject to fusion

Since 0.3.0

iterM :: Monad m => (a -> m ()) -> ConduitT a a m () #

Apply a monadic action on all values in a stream.

This `Conduit` can be used to perform a monadic side-effect for every value, whilst passing the value through the `Conduit` as-is.

    iterM f = mapM (\a -> f a >>= \() -> return a)

Subject to fusion

Since 0.5.6

scanlM :: Monad m => (a -> s -> m (s, b)) -> s -> ConduitT a b m () #

Deprecated: Use mapAccumM instead

Deprecated synonym for `mapAccumM`

Since 1.0.6

scanM :: Monad m => (a -> b -> m b) -> b -> ConduitT a b m b #

Monadic `scanl`.

Subject to fusion

Since 1.1.1

mapAccumM :: Monad m => (a -> s -> m (s, b)) -> s -> ConduitT a b m s #

Monadic `mapAccum`.

Subject to fusion

Since 1.1.1

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

Apply a monadic transformation that may fail to all values in a stream, discarding the failures.

Subject to fusion

Since 0.5.1

mapFoldableM :: (Monad m, Foldable f) => (a -> m (f b)) -> ConduitT a b m () #

Monadic variant of `mapFoldable`.

Subject to fusion

Since 1.0.6

concatMapM :: Monad m => (a -> m [b]) -> ConduitT a b m () #

Apply a monadic transformation to all values in a stream, concatenating the output values.

Subject to fusion

Since 0.3.0

concatMapAccumM :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> ConduitT a b m () #

`concatMapM` with a strict accumulator.

Subject to fusion

Since 0.3.0

# Misc

sequence #

Arguments

:: forall (m :: Type -> Type) i o. Monad m |
=> ConduitT i o m o | `Pipe` to run repeatedly
-> ConduitT i o m () |

Run a `Pipe` repeatedly, and output its result value downstream. Stops when no more input is available from upstream.

Since 0.5.0