{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE Trustworthy #-}
module Data.Conduit.List
(
sourceList
, sourceNull
, unfold
, unfoldEither
, unfoldM
, unfoldEitherM
, enumFromTo
, iterate
, replicate
, replicateM
, fold
, foldMap
, uncons
, unconsEither
, take
, drop
, head
, peek
, consume
, sinkNull
, foldMapM
, foldM
, unconsM
, unconsEitherM
, mapM_
, map
, mapMaybe
, mapFoldable
, catMaybes
, concat
, concatMap
, concatMapAccum
, scanl
, scan
, mapAccum
, chunksOf
, groupBy
, groupOn1
, isolate
, filter
, mapM
, iterM
, scanlM
, scanM
, mapAccumM
, mapMaybeM
, mapFoldableM
, concatMapM
, concatMapAccumM
, sequence
) where
import qualified Prelude
import Prelude
( ($), return, (==), (-), Int
, (.), id, Maybe (..), Monad
, Either (..)
, Bool (..)
, (>>)
, (>>=)
, seq
, otherwise
, Enum, Eq
, maybe
, (<=)
, (>)
, error
, (++)
, show
)
import Data.Monoid (Monoid, mempty, mappend)
import qualified Data.Foldable as F
import Data.Conduit
import Data.Conduit.Internal.Conduit (unconsM, unconsEitherM)
import Data.Conduit.Internal.Fusion
import Data.Conduit.Internal.List.Stream
import qualified Data.Conduit.Internal as CI
import Data.Functor.Identity (Identity (runIdentity))
import Control.Monad (when, (<=<), liftM, void)
import Control.Monad.Trans.Class (lift)
#include "fusion-macros.h"
unfold, unfoldC :: Monad m
=> (b -> Maybe (a, b))
-> b
-> ConduitT i a m ()
unfoldC :: forall (m :: * -> *) b a i.
Monad m =>
(b -> Maybe (a, b)) -> b -> ConduitT i a m ()
unfoldC b -> Maybe (a, b)
f =
forall {m :: * -> *} {i}. Monad m => b -> ConduitT i a m ()
go
where
go :: b -> ConduitT i a m ()
go b
seed =
case b -> Maybe (a, b)
f b
seed of
Just (a
a, b
seed') -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> b -> ConduitT i a m ()
go b
seed'
Maybe (a, b)
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE unfoldC #-}
STREAMING(unfold, unfoldC, unfoldS, f x)
unfoldEither, unfoldEitherC :: Monad m
=> (b -> Either r (a, b))
-> b
-> ConduitT i a m r
unfoldEitherC :: forall (m :: * -> *) b r a i.
Monad m =>
(b -> Either r (a, b)) -> b -> ConduitT i a m r
unfoldEitherC b -> Either r (a, b)
f =
forall {m :: * -> *} {i}. Monad m => b -> ConduitT i a m r
go
where
go :: b -> ConduitT i a m r
go b
seed =
case b -> Either r (a, b)
f b
seed of
Right (a
a, b
seed') -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> b -> ConduitT i a m r
go b
seed'
Left r
r -> forall (m :: * -> *) a. Monad m => a -> m a
return r
r
{-# INLINE unfoldEitherC #-}
STREAMING(unfoldEither, unfoldEitherC, unfoldEitherS, f x)
unfoldM, unfoldMC :: Monad m
=> (b -> m (Maybe (a, b)))
-> b
-> ConduitT i a m ()
unfoldMC :: forall (m :: * -> *) b a i.
Monad m =>
(b -> m (Maybe (a, b))) -> b -> ConduitT i a m ()
unfoldMC b -> m (Maybe (a, b))
f =
forall {i}. b -> ConduitT i a m ()
go
where
go :: b -> ConduitT i a m ()
go b
seed = do
Maybe (a, b)
mres <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ b -> m (Maybe (a, b))
f b
seed
case Maybe (a, b)
mres of
Just (a
a, b
seed') -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> b -> ConduitT i a m ()
go b
seed'
Maybe (a, b)
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
STREAMING(unfoldM, unfoldMC, unfoldMS, f seed)
unfoldEitherM, unfoldEitherMC :: Monad m
=> (b -> m (Either r (a, b)))
-> b
-> ConduitT i a m r
unfoldEitherMC :: forall (m :: * -> *) b r a i.
Monad m =>
(b -> m (Either r (a, b))) -> b -> ConduitT i a m r
unfoldEitherMC b -> m (Either r (a, b))
f =
forall {i}. b -> ConduitT i a m r
go
where
go :: b -> ConduitT i a m r
go b
seed = do
Either r (a, b)
mres <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ b -> m (Either r (a, b))
f b
seed
case Either r (a, b)
mres of
Right (a
a, b
seed') -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> b -> ConduitT i a m r
go b
seed'
Left r
r -> forall (m :: * -> *) a. Monad m => a -> m a
return r
r
STREAMING(unfoldEitherM, unfoldEitherMC, unfoldEitherMS, f seed)
uncons :: SealedConduitT () o Identity ()
-> Maybe (o, SealedConduitT () o Identity ())
uncons :: forall o.
SealedConduitT () o Identity ()
-> Maybe (o, SealedConduitT () o Identity ())
uncons = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) o.
Monad m =>
SealedConduitT () o m () -> m (Maybe (o, SealedConduitT () o m ()))
unconsM
unconsEither :: SealedConduitT () o Identity r
-> Either r (o, SealedConduitT () o Identity r)
unconsEither :: forall o r.
SealedConduitT () o Identity r
-> Either r (o, SealedConduitT () o Identity r)
unconsEither = forall a. Identity a -> a
runIdentity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) o r.
Monad m =>
SealedConduitT () o m r
-> m (Either r (o, SealedConduitT () o m r))
unconsEitherM
sourceList, sourceListC :: Monad m => [a] -> ConduitT i a m ()
sourceListC :: forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
sourceListC = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
Prelude.mapM_ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE sourceListC #-}
STREAMING(sourceList, sourceListC, sourceListS, xs)
enumFromTo, enumFromToC :: (Enum a, Prelude.Ord a, Monad m)
=> a
-> a
-> ConduitT i a m ()
enumFromToC :: forall a (m :: * -> *) i.
(Enum a, Ord a, Monad m) =>
a -> a -> ConduitT i a m ()
enumFromToC a
x0 a
y =
forall {m :: * -> *} {i}. Monad m => a -> ConduitT i a m ()
loop a
x0
where
loop :: a -> ConduitT i a m ()
loop a
x
| a
x forall a. Ord a => a -> a -> Bool
Prelude.> a
y = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> ConduitT i a m ()
loop (forall a. Enum a => a -> a
Prelude.succ a
x)
{-# INLINE enumFromToC #-}
STREAMING(enumFromTo, enumFromToC, enumFromToS, x0 y)
iterate, iterateC :: Monad m => (a -> a) -> a -> ConduitT i a m ()
iterateC :: forall (m :: * -> *) a i.
Monad m =>
(a -> a) -> a -> ConduitT i a m ()
iterateC a -> a
f =
forall {m :: * -> *} {i} {b}. Monad m => a -> ConduitT i a m b
go
where
go :: a -> ConduitT i a m b
go a
a = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> ConduitT i a m b
go (a -> a
f a
a)
{-# INLINE iterateC #-}
STREAMING(iterate, iterateC, iterateS, f a)
replicate, replicateC :: Monad m => Int -> a -> ConduitT i a m ()
replicateC :: forall (m :: * -> *) a i. Monad m => Int -> a -> ConduitT i a m ()
replicateC Int
cnt0 a
a =
forall {t} {m :: * -> *} {i}.
(Ord t, Num t, Monad m) =>
t -> ConduitT i a m ()
loop Int
cnt0
where
loop :: t -> ConduitT i a m ()
loop t
i
| t
i forall a. Ord a => a -> a -> Bool
<= t
0 = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> t -> ConduitT i a m ()
loop (t
i forall a. Num a => a -> a -> a
- t
1)
{-# INLINE replicateC #-}
STREAMING(replicate, replicateC, replicateS, cnt0 a)
replicateM, replicateMC :: Monad m => Int -> m a -> ConduitT i a m ()
replicateMC :: forall (m :: * -> *) a i.
Monad m =>
Int -> m a -> ConduitT i a m ()
replicateMC Int
cnt0 m a
ma =
forall {t} {i}. (Ord t, Num t) => t -> ConduitT i a m ()
loop Int
cnt0
where
loop :: t -> ConduitT i a m ()
loop t
i
| t
i forall a. Ord a => a -> a -> Bool
<= t
0 = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m a
ma forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> t -> ConduitT i a m ()
loop (t
i forall a. Num a => a -> a -> a
- t
1)
{-# INLINE replicateMC #-}
STREAMING(replicateM, replicateMC, replicateMS, cnt0 ma)
fold, foldC :: Monad m
=> (b -> a -> b)
-> b
-> ConduitT a o m b
foldC :: forall (m :: * -> *) b a o.
Monad m =>
(b -> a -> b) -> b -> ConduitT a o m b
foldC b -> a -> b
f =
forall {m :: * -> *} {o}. Monad m => b -> ConduitT a o m b
loop
where
loop :: b -> ConduitT a o m b
loop !b
accum = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return b
accum) (b -> ConduitT a o m b
loop forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> a -> b
f b
accum)
{-# INLINE foldC #-}
STREAMING(fold, foldC, foldS, f accum)
foldM, foldMC :: Monad m
=> (b -> a -> m b)
-> b
-> ConduitT a o m b
foldMC :: forall (m :: * -> *) b a o.
Monad m =>
(b -> a -> m b) -> b -> ConduitT a o m b
foldMC b -> a -> m b
f =
forall {o}. b -> ConduitT a o m b
loop
where
loop :: b -> ConduitT a o m b
loop b
accum = do
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return b
accum) a -> ConduitT a o m b
go
where
go :: a -> ConduitT a o m b
go a
a = do
b
accum' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ b -> a -> m b
f b
accum a
a
b
accum' seq :: forall a b. a -> b -> b
`seq` b -> ConduitT a o m b
loop b
accum'
{-# INLINE foldMC #-}
STREAMING(foldM, foldMC, foldMS, f accum)
connectFold :: Monad m => ConduitT () a m () -> (b -> a -> b) -> b -> m b
connectFold :: forall (m :: * -> *) a b.
Monad m =>
ConduitT () a m () -> (b -> a -> b) -> b -> m b
connectFold (CI.ConduitT forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
src0) b -> a -> b
f =
forall {m :: * -> *} {i}.
Monad m =>
Pipe () i a () m () -> b -> m b
go (forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
src0 forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
CI.Done)
where
go :: Pipe () i a () m () -> b -> m b
go (CI.Done ()) b
b = forall (m :: * -> *) a. Monad m => a -> m a
return b
b
go (CI.HaveOutput Pipe () i a () m ()
src a
a) b
b = Pipe () i a () m () -> b -> m b
go Pipe () i a () m ()
src forall a b. (a -> b) -> a -> b
Prelude.$! b -> a -> b
f b
b a
a
go (CI.NeedInput i -> Pipe () i a () m ()
_ () -> Pipe () i a () m ()
c) b
b = Pipe () i a () m () -> b -> m b
go (() -> Pipe () i a () m ()
c ()) b
b
go (CI.Leftover Pipe () i a () m ()
src ()) b
b = Pipe () i a () m () -> b -> m b
go Pipe () i a () m ()
src b
b
go (CI.PipeM m (Pipe () i a () m ())
msrc) b
b = do
Pipe () i a () m ()
src <- m (Pipe () i a () m ())
msrc
Pipe () i a () m () -> b -> m b
go Pipe () i a () m ()
src b
b
{-# INLINE connectFold #-}
{-# RULES "conduit: $$ fold" forall src f b. runConduit (src .| fold f b) = connectFold src f b #-}
connectFoldM :: Monad m => ConduitT () a m () -> (b -> a -> m b) -> b -> m b
connectFoldM :: forall (m :: * -> *) a b.
Monad m =>
ConduitT () a m () -> (b -> a -> m b) -> b -> m b
connectFoldM (CI.ConduitT forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
src0) b -> a -> m b
f =
forall {i}. Pipe () i a () m () -> b -> m b
go (forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
src0 forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
CI.Done)
where
go :: Pipe () i a () m () -> b -> m b
go (CI.Done ()) b
b = forall (m :: * -> *) a. Monad m => a -> m a
return b
b
go (CI.HaveOutput Pipe () i a () m ()
src a
a) b
b = do
!b
b' <- b -> a -> m b
f b
b a
a
Pipe () i a () m () -> b -> m b
go Pipe () i a () m ()
src b
b'
go (CI.NeedInput i -> Pipe () i a () m ()
_ () -> Pipe () i a () m ()
c) b
b = Pipe () i a () m () -> b -> m b
go (() -> Pipe () i a () m ()
c ()) b
b
go (CI.Leftover Pipe () i a () m ()
src ()) b
b = Pipe () i a () m () -> b -> m b
go Pipe () i a () m ()
src b
b
go (CI.PipeM m (Pipe () i a () m ())
msrc) b
b = do
Pipe () i a () m ()
src <- m (Pipe () i a () m ())
msrc
Pipe () i a () m () -> b -> m b
go Pipe () i a () m ()
src b
b
{-# INLINE connectFoldM #-}
{-# RULES "conduit: $$ foldM" forall src f b. runConduit (src .| foldM f b) = connectFoldM src f b #-}
foldMap :: (Monad m, Monoid b)
=> (a -> b)
-> ConduitT a o m b
INLINE_RULE(foldMap, f, let combiner accum = mappend accum . f in fold combiner mempty)
foldMapM :: (Monad m, Monoid b)
=> (a -> m b)
-> ConduitT a o m b
INLINE_RULE(foldMapM, f, let combiner accum = liftM (mappend accum) . f in foldM combiner mempty)
mapM_, mapM_C :: Monad m
=> (a -> m ())
-> ConduitT a o m ()
mapM_C :: forall (m :: * -> *) a o.
Monad m =>
(a -> m ()) -> ConduitT a o m ()
mapM_C a -> m ()
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m ()
f
{-# INLINE mapM_C #-}
STREAMING(mapM_, mapM_C, mapM_S, f)
srcMapM_ :: Monad m => ConduitT () a m () -> (a -> m ()) -> m ()
srcMapM_ :: forall (m :: * -> *) a.
Monad m =>
ConduitT () a m () -> (a -> m ()) -> m ()
srcMapM_ (CI.ConduitT forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
src) a -> m ()
f =
forall {i}. Pipe () i a () m () -> m ()
go (forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
src forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
CI.Done)
where
go :: Pipe () i a () m () -> m ()
go (CI.Done ()) = forall (m :: * -> *) a. Monad m => a -> m a
return ()
go (CI.PipeM m (Pipe () i a () m ())
mp) = m (Pipe () i a () m ())
mp forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pipe () i a () m () -> m ()
go
go (CI.Leftover Pipe () i a () m ()
p ()) = Pipe () i a () m () -> m ()
go Pipe () i a () m ()
p
go (CI.HaveOutput Pipe () i a () m ()
p a
o) = a -> m ()
f a
o forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Pipe () i a () m () -> m ()
go Pipe () i a () m ()
p
go (CI.NeedInput i -> Pipe () i a () m ()
_ () -> Pipe () i a () m ()
c) = Pipe () i a () m () -> m ()
go (() -> Pipe () i a () m ()
c ())
{-# INLINE srcMapM_ #-}
{-# RULES "conduit: connect to mapM_" [2] forall f src. runConduit (src .| mapM_ f) = srcMapM_ src f #-}
drop, dropC :: Monad m
=> Int
-> ConduitT a o m ()
dropC :: forall (m :: * -> *) a o. Monad m => Int -> ConduitT a o m ()
dropC =
forall {t} {m :: * -> *} {i} {o}.
(Ord t, Num t, Monad m) =>
t -> ConduitT i o m ()
loop
where
loop :: t -> ConduitT i o m ()
loop t
i | t
i forall a. Ord a => a -> a -> Bool
<= t
0 = forall (m :: * -> *) a. Monad m => a -> m a
return ()
loop t
count = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (\i
_ -> t -> ConduitT i o m ()
loop (t
count forall a. Num a => a -> a -> a
- t
1))
{-# INLINE dropC #-}
STREAMING(drop, dropC, dropS, i)
take, takeC :: Monad m
=> Int
-> ConduitT a o m [a]
takeC :: forall (m :: * -> *) a o. Monad m => Int -> ConduitT a o m [a]
takeC =
forall {t} {m :: * -> *} {a} {c} {o}.
(Ord t, Num t, Monad m) =>
([a] -> c) -> t -> ConduitT a o m c
loop forall a. a -> a
id
where
loop :: ([a] -> c) -> t -> ConduitT a o m c
loop [a] -> c
front t
count | t
count forall a. Ord a => a -> a -> Bool
<= t
0 = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [a] -> c
front []
loop [a] -> c
front t
count = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe
(forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [a] -> c
front [])
(\a
x -> ([a] -> c) -> t -> ConduitT a o m c
loop ([a] -> c
front forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
xforall a. a -> [a] -> [a]
:)) (t
count forall a. Num a => a -> a -> a
- t
1))
{-# INLINE takeC #-}
STREAMING(take, takeC, takeS, i)
head, headC :: Monad m => ConduitT a o m (Maybe a)
headC :: forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
headC = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
{-# INLINE headC #-}
STREAMING0(head, headC, headS)
peek :: Monad m => ConduitT a o m (Maybe a)
peek :: forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
peek = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) (\a
x -> forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover a
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (forall a. a -> Maybe a
Just a
x))
map, mapC :: Monad m => (a -> b) -> ConduitT a b m ()
mapC :: forall (m :: * -> *) a b. Monad m => (a -> b) -> ConduitT a b m ()
mapC a -> b
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f
{-# INLINE mapC #-}
STREAMING(map, mapC, mapS, f)
mapM, mapMC :: Monad m => (a -> m b) -> ConduitT a b m ()
mapMC :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ConduitT a b m ()
mapMC a -> m b
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ \a
a -> forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (a -> m b
f a
a) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE mapMC #-}
STREAMING(mapM, mapMC, mapMS, f)
iterM, iterMC :: Monad m => (a -> m ()) -> ConduitT a a m ()
iterMC :: forall (m :: * -> *) a. Monad m => (a -> m ()) -> ConduitT a a m ()
iterMC a -> m ()
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ \a
a -> forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (a -> m ()
f a
a) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
a
{-# INLINE iterMC #-}
STREAMING(iterM, iterMC, iterMS, f)
mapMaybe, mapMaybeC :: Monad m => (a -> Maybe b) -> ConduitT a b m ()
mapMaybeC :: forall (m :: * -> *) a b.
Monad m =>
(a -> Maybe b) -> ConduitT a b m ()
mapMaybeC a -> Maybe b
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe b
f
{-# INLINE mapMaybeC #-}
STREAMING(mapMaybe, mapMaybeC, mapMaybeS, f)
mapMaybeM, mapMaybeMC :: Monad m => (a -> m (Maybe b)) -> ConduitT a b m ()
mapMaybeMC :: forall (m :: * -> *) a b.
Monad m =>
(a -> m (Maybe b)) -> ConduitT a b m ()
mapMaybeMC a -> m (Maybe b)
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m (Maybe b)
f
{-# INLINE mapMaybeMC #-}
STREAMING(mapMaybeM, mapMaybeMC, mapMaybeMS, f)
catMaybes, catMaybesC :: Monad m => ConduitT (Maybe a) a m ()
catMaybesC :: forall (m :: * -> *) a. Monad m => ConduitT (Maybe a) a m ()
catMaybesC = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE catMaybesC #-}
STREAMING0(catMaybes, catMaybesC, catMaybesS)
concat, concatC :: (Monad m, F.Foldable f) => ConduitT (f a) a m ()
concatC :: forall (m :: * -> *) (f :: * -> *) a.
(Monad m, Foldable f) =>
ConduitT (f a) a m ()
concatC = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
F.mapM_ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE concatC #-}
STREAMING0(concat, concatC, concatS)
concatMap, concatMapC :: Monad m => (a -> [b]) -> ConduitT a b m ()
concatMapC :: forall (m :: * -> *) a b.
Monad m =>
(a -> [b]) -> ConduitT a b m ()
concatMapC a -> [b]
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
sourceList forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [b]
f
{-# INLINE concatMapC #-}
STREAMING(concatMap, concatMapC, concatMapS, f)
concatMapM, concatMapMC :: Monad m => (a -> m [b]) -> ConduitT a b m ()
concatMapMC :: forall (m :: * -> *) a b.
Monad m =>
(a -> m [b]) -> ConduitT a b m ()
concatMapMC a -> m [b]
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
sourceList forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m [b]
f
{-# INLINE concatMapMC #-}
STREAMING(concatMapM, concatMapMC, concatMapMS, f)
concatMapAccum, concatMapAccumC :: Monad m => (a -> accum -> (accum, [b])) -> accum -> ConduitT a b m ()
concatMapAccumC :: forall (m :: * -> *) a accum b.
Monad m =>
(a -> accum -> (accum, [b])) -> accum -> ConduitT a b m ()
concatMapAccumC a -> accum -> (accum, [b])
f accum
x0 = forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> (s, b)) -> s -> ConduitT a b m s
mapAccum a -> accum -> (accum, [b])
f accum
x0) forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| forall (m :: * -> *) (f :: * -> *) a.
(Monad m, Foldable f) =>
ConduitT (f a) a m ()
concat
{-# INLINE concatMapAccumC #-}
STREAMING(concatMapAccum, concatMapAccumC, concatMapAccumS, f x0)
scanl :: Monad m => (a -> s -> (s, b)) -> s -> ConduitT a b m ()
scanl :: forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> (s, b)) -> s -> ConduitT a b m ()
scanl a -> s -> (s, b)
f s
s = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> (s, b)) -> s -> ConduitT a b m s
mapAccum a -> s -> (s, b)
f s
s
{-# DEPRECATED scanl "Use mapAccum instead" #-}
scanlM :: Monad m => (a -> s -> m (s, b)) -> s -> ConduitT a b m ()
scanlM :: forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> m (s, b)) -> s -> ConduitT a b m ()
scanlM a -> s -> m (s, b)
f s
s = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> m (s, b)) -> s -> ConduitT a b m s
mapAccumM a -> s -> m (s, b)
f s
s
{-# DEPRECATED scanlM "Use mapAccumM instead" #-}
mapAccum, mapAccumC :: Monad m => (a -> s -> (s, b)) -> s -> ConduitT a b m s
mapAccumC :: forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> (s, b)) -> s -> ConduitT a b m s
mapAccumC a -> s -> (s, b)
f =
forall {m :: * -> *}. Monad m => s -> ConduitT a b m s
loop
where
loop :: s -> ConduitT a b m s
loop !s
s = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return s
s) a -> ConduitT a b m s
go
where
go :: a -> ConduitT a b m s
go a
a = case a -> s -> (s, b)
f a
a s
s of
(s
s', b
b) -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> s -> ConduitT a b m s
loop s
s'
STREAMING(mapAccum, mapAccumC, mapAccumS, f s)
mapAccumM, mapAccumMC :: Monad m => (a -> s -> m (s, b)) -> s -> ConduitT a b m s
mapAccumMC :: forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> m (s, b)) -> s -> ConduitT a b m s
mapAccumMC a -> s -> m (s, b)
f =
s -> ConduitT a b m s
loop
where
loop :: s -> ConduitT a b m s
loop !s
s = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return s
s) a -> ConduitT a b m s
go
where
go :: a -> ConduitT a b m s
go a
a = do (s
s', b
b) <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ a -> s -> m (s, b)
f a
a s
s
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
b
s -> ConduitT a b m s
loop s
s'
{-# INLINE mapAccumMC #-}
STREAMING(mapAccumM, mapAccumMC, mapAccumMS, f s)
scan :: Monad m => (a -> b -> b) -> b -> ConduitT a b m b
INLINE_RULE(scan, f, mapAccum (\a b -> let r = f a b in (r, r)))
scanM :: Monad m => (a -> b -> m b) -> b -> ConduitT a b m b
INLINE_RULE(scanM, f, mapAccumM (\a b -> f a b >>= \r -> return (r, r)))
concatMapAccumM, concatMapAccumMC :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> ConduitT a b m ()
concatMapAccumMC :: forall (m :: * -> *) a accum b.
Monad m =>
(a -> accum -> m (accum, [b])) -> accum -> ConduitT a b m ()
concatMapAccumMC a -> accum -> m (accum, [b])
f accum
x0 = forall (f :: * -> *) a. Functor f => f a -> f ()
void (forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> m (s, b)) -> s -> ConduitT a b m s
mapAccumM a -> accum -> m (accum, [b])
f accum
x0) forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| forall (m :: * -> *) (f :: * -> *) a.
(Monad m, Foldable f) =>
ConduitT (f a) a m ()
concat
{-# INLINE concatMapAccumMC #-}
STREAMING(concatMapAccumM, concatMapAccumMC, concatMapAccumMS, f x0)
mapFoldable, mapFoldableC :: (Monad m, F.Foldable f) => (a -> f b) -> ConduitT a b m ()
mapFoldableC :: forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Foldable f) =>
(a -> f b) -> ConduitT a b m ()
mapFoldableC a -> f b
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
F.mapM_ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> f b
f
{-# INLINE mapFoldableC #-}
STREAMING(mapFoldable, mapFoldableC, mapFoldableS, f)
mapFoldableM, mapFoldableMC :: (Monad m, F.Foldable f) => (a -> m (f b)) -> ConduitT a b m ()
mapFoldableMC :: forall (m :: * -> *) (f :: * -> *) a b.
(Monad m, Foldable f) =>
(a -> m (f b)) -> ConduitT a b m ()
mapFoldableMC a -> m (f b)
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
F.mapM_ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m (f b)
f
{-# INLINE mapFoldableMC #-}
STREAMING(mapFoldableM, mapFoldableMC, mapFoldableMS, f)
consume, consumeC :: Monad m => ConduitT a o m [a]
consumeC :: forall (m :: * -> *) a o. Monad m => ConduitT a o m [a]
consumeC =
forall {m :: * -> *} {a} {c} {o}.
Monad m =>
([a] -> c) -> ConduitT a o m c
loop forall a. a -> a
id
where
loop :: ([a] -> c) -> ConduitT a o m c
loop [a] -> c
front = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [a] -> c
front []) (\a
x -> ([a] -> c) -> ConduitT a o m c
loop forall a b. (a -> b) -> a -> b
$ [a] -> c
front forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
xforall a. a -> [a] -> [a]
:))
{-# INLINE consumeC #-}
STREAMING0(consume, consumeC, consumeS)
chunksOf :: Monad m => Int -> ConduitT a [a] m ()
chunksOf :: forall (m :: * -> *) a. Monad m => Int -> ConduitT a [a] m ()
chunksOf Int
n = if Int
n forall a. Ord a => a -> a -> Bool
> Int
0 then forall {m :: * -> *} {a}.
Monad m =>
Int -> ([a] -> [a]) -> ConduitT a [a] m ()
loop Int
n forall a. a -> a
id else forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"chunksOf size must be positive (given " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Int
n forall a. [a] -> [a] -> [a]
++ [Char]
")"
where
loop :: Int -> ([a] -> [a]) -> ConduitT a [a] m ()
loop Int
0 [a] -> [a]
rest = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield ([a] -> [a]
rest []) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Int -> ([a] -> [a]) -> ConduitT a [a] m ()
loop Int
n forall a. a -> a
id
loop Int
count [a] -> [a]
rest = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe a
ma -> case Maybe a
ma of
Maybe a
Nothing -> case [a] -> [a]
rest [] of
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
[a]
nonempty -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield [a]
nonempty
Just a
a -> Int -> ([a] -> [a]) -> ConduitT a [a] m ()
loop (Int
count forall a. Num a => a -> a -> a
- Int
1) ([a] -> [a]
rest forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
a forall a. a -> [a] -> [a]
:))
groupBy, groupByC :: Monad m => (a -> a -> Bool) -> ConduitT a [a] m ()
groupByC :: forall (m :: * -> *) a.
Monad m =>
(a -> a -> Bool) -> ConduitT a [a] m ()
groupByC a -> a -> Bool
f =
ConduitT a [a] m ()
start
where
start :: ConduitT a [a] m ()
start = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (forall {m :: * -> *}.
Monad m =>
([a] -> [a]) -> a -> ConduitT a [a] m ()
loop forall a. a -> a
id)
loop :: ([a] -> [a]) -> a -> ConduitT a [a] m ()
loop [a] -> [a]
rest a
x =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (a
x forall a. a -> [a] -> [a]
: [a] -> [a]
rest [])) a -> ConduitT a [a] m ()
go
where
go :: a -> ConduitT a [a] m ()
go a
y
| a -> a -> Bool
f a
x a
y = ([a] -> [a]) -> a -> ConduitT a [a] m ()
loop ([a] -> [a]
rest forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
yforall a. a -> [a] -> [a]
:)) a
x
| Bool
otherwise = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (a
x forall a. a -> [a] -> [a]
: [a] -> [a]
rest []) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ([a] -> [a]) -> a -> ConduitT a [a] m ()
loop forall a. a -> a
id a
y
STREAMING(groupBy, groupByC, groupByS, f)
groupOn1, groupOn1C :: (Monad m, Eq b)
=> (a -> b)
-> ConduitT a (a, [a]) m ()
groupOn1C :: forall (m :: * -> *) b a.
(Monad m, Eq b) =>
(a -> b) -> ConduitT a (a, [a]) m ()
groupOn1C a -> b
f =
ConduitT a (a, [a]) m ()
start
where
start :: ConduitT a (a, [a]) m ()
start = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (forall {m :: * -> *}.
Monad m =>
([a] -> [a]) -> a -> ConduitT a (a, [a]) m ()
loop forall a. a -> a
id)
loop :: ([a] -> [a]) -> a -> ConduitT a (a, [a]) m ()
loop [a] -> [a]
rest a
x =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (a
x, [a] -> [a]
rest [])) a -> ConduitT a (a, [a]) m ()
go
where
go :: a -> ConduitT a (a, [a]) m ()
go a
y
| a -> b
f a
x forall a. Eq a => a -> a -> Bool
== a -> b
f a
y = ([a] -> [a]) -> a -> ConduitT a (a, [a]) m ()
loop ([a] -> [a]
rest forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
yforall a. a -> [a] -> [a]
:)) a
x
| Bool
otherwise = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (a
x, [a] -> [a]
rest []) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ([a] -> [a]) -> a -> ConduitT a (a, [a]) m ()
loop forall a. a -> a
id a
y
STREAMING(groupOn1, groupOn1C, groupOn1S, f)
isolate, isolateC :: Monad m => Int -> ConduitT a a m ()
isolateC :: forall (m :: * -> *) a. Monad m => Int -> ConduitT a a m ()
isolateC =
forall {t} {m :: * -> *} {o}.
(Ord t, Num t, Monad m) =>
t -> ConduitT o o m ()
loop
where
loop :: t -> ConduitT o o m ()
loop t
count | t
count forall a. Ord a => a -> a -> Bool
<= t
0 = forall (m :: * -> *) a. Monad m => a -> m a
return ()
loop t
count = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (\o
x -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield o
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> t -> ConduitT o o m ()
loop (t
count forall a. Num a => a -> a -> a
- t
1))
STREAMING(isolate, isolateC, isolateS, count)
filter, filterC :: Monad m => (a -> Bool) -> ConduitT a a m ()
filterC :: forall (m :: * -> *) a. Monad m => (a -> Bool) -> ConduitT a a m ()
filterC a -> Bool
f = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ \a
i -> forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (a -> Bool
f a
i) (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
i)
STREAMING(filter, filterC, filterS, f)
filterFuseRight
:: Monad m
=> ConduitT i o m ()
-> (o -> Bool)
-> ConduitT i o m ()
filterFuseRight :: forall (m :: * -> *) i o.
Monad m =>
ConduitT i o m () -> (o -> Bool) -> ConduitT i o m ()
filterFuseRight (CI.ConduitT forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b
src) o -> Bool
f = forall i o (m :: * -> *) r.
(forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
CI.ConduitT forall a b. (a -> b) -> a -> b
$ \() -> Pipe i i o () m b
rest -> let
go :: Pipe i i o () m () -> Pipe i i o () m b
go (CI.Done ()) = () -> Pipe i i o () m b
rest ()
go (CI.PipeM m (Pipe i i o () m ())
mp) = forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
CI.PipeM (forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe i i o () m () -> Pipe i i o () m b
go m (Pipe i i o () m ())
mp)
go (CI.Leftover Pipe i i o () m ()
p i
i) = forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
CI.Leftover (Pipe i i o () m () -> Pipe i i o () m b
go Pipe i i o () m ()
p) i
i
go (CI.HaveOutput Pipe i i o () m ()
p o
o)
| o -> Bool
f o
o = forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
CI.HaveOutput (Pipe i i o () m () -> Pipe i i o () m b
go Pipe i i o () m ()
p) o
o
| Bool
otherwise = Pipe i i o () m () -> Pipe i i o () m b
go Pipe i i o () m ()
p
go (CI.NeedInput i -> Pipe i i o () m ()
p () -> Pipe i i o () m ()
c) = forall l i o u (m :: * -> *) r.
(i -> Pipe l i o u m r)
-> (u -> Pipe l i o u m r) -> Pipe l i o u m r
CI.NeedInput (Pipe i i o () m () -> Pipe i i o () m b
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe i i o () m ()
p) (Pipe i i o () m () -> Pipe i i o () m b
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i i o () m ()
c)
in Pipe i i o () m () -> Pipe i i o () m b
go (forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b
src forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
CI.Done)
{-# RULES "conduit: source/filter fusion .|" forall f src. src .| filter f = filterFuseRight src f #-}
{-# INLINE filterFuseRight #-}
sinkNull, sinkNullC :: Monad m => ConduitT i o m ()
sinkNullC :: forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
sinkNullC = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ \i
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE sinkNullC #-}
STREAMING0(sinkNull, sinkNullC, sinkNullS)
srcSinkNull :: Monad m => ConduitT () o m () -> m ()
srcSinkNull :: forall (m :: * -> *) o. Monad m => ConduitT () o m () -> m ()
srcSinkNull (CI.ConduitT forall b. (() -> Pipe () () o () m b) -> Pipe () () o () m b
src) =
forall {m :: * -> *} {i} {o}.
Monad m =>
Pipe () i o () m () -> m ()
go (forall b. (() -> Pipe () () o () m b) -> Pipe () () o () m b
src forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
CI.Done)
where
go :: Pipe () i o () m () -> m ()
go (CI.Done ()) = forall (m :: * -> *) a. Monad m => a -> m a
return ()
go (CI.PipeM m (Pipe () i o () m ())
mp) = m (Pipe () i o () m ())
mp forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pipe () i o () m () -> m ()
go
go (CI.Leftover Pipe () i o () m ()
p ()) = Pipe () i o () m () -> m ()
go Pipe () i o () m ()
p
go (CI.HaveOutput Pipe () i o () m ()
p o
_) = Pipe () i o () m () -> m ()
go Pipe () i o () m ()
p
go (CI.NeedInput i -> Pipe () i o () m ()
_ () -> Pipe () i o () m ()
c) = Pipe () i o () m () -> m ()
go (() -> Pipe () i o () m ()
c ())
{-# INLINE srcSinkNull #-}
{-# RULES "conduit: connect to sinkNull" forall src. runConduit (src .| sinkNull) = srcSinkNull src #-}
sourceNull, sourceNullC :: Monad m => ConduitT i o m ()
sourceNullC :: forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
sourceNullC = forall (m :: * -> *) a. Monad m => a -> m a
return ()
{-# INLINE sourceNullC #-}
STREAMING0(sourceNull, sourceNullC, sourceNullS)
sequence :: Monad m
=> ConduitT i o m o
-> ConduitT i o m ()
sequence :: forall (m :: * -> *) i o.
Monad m =>
ConduitT i o m o -> ConduitT i o m ()
sequence ConduitT i o m o
sink =
ConduitT i o m ()
self
where
self :: ConduitT i o m ()
self = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ \i
i -> forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover i
i forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT i o m o
sink forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield