{-# OPTIONS_HADDOCK not-home #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Conduit.Internal.Conduit
    ( -- ** Types
      ConduitT (..)
    , ConduitM
    , Source
    , Producer
    , Sink
    , Consumer
    , Conduit
    , Flush (..)
      -- *** Newtype wrappers
    , ZipSource (..)
    , ZipSink (..)
    , ZipConduit (..)
      -- ** Sealed
    , SealedConduitT (..)
    , sealConduitT
    , unsealConduitT
      -- ** Primitives
    , await
    , awaitForever
    , yield
    , yieldM
    , leftover
    , runConduit
    , runConduitPure
    , runConduitRes
    , fuse
    , connect
    , unconsM
    , unconsEitherM
      -- ** Composition
    , connectResume
    , connectResumeConduit
    , fuseLeftovers
    , fuseReturnLeftovers
    , ($$+)
    , ($$++)
    , ($$+-)
    , ($=+)
    , (=$$+)
    , (=$$++)
    , (=$$+-)
    , ($$)
    , ($=)
    , (=$)
    , (=$=)
    , (.|)
      -- ** Generalizing
    , sourceToPipe
    , sinkToPipe
    , conduitToPipe
    , toProducer
    , toConsumer
      -- ** Cleanup
    , bracketP
      -- ** Exceptions
    , catchC
    , handleC
    , tryC
      -- ** Utilities
    , Data.Conduit.Internal.Conduit.transPipe
    , Data.Conduit.Internal.Conduit.mapOutput
    , Data.Conduit.Internal.Conduit.mapOutputMaybe
    , Data.Conduit.Internal.Conduit.mapInput
    , Data.Conduit.Internal.Conduit.mapInputM
    , zipSinks
    , zipSources
    , zipSourcesApp
    , zipConduitApp
    , mergeSource
    , passthroughSink
    , sourceToList
    , fuseBoth
    , fuseBothMaybe
    , fuseUpstream
    , sequenceSources
    , sequenceSinks
    , sequenceConduits
    ) where

import Control.Applicative (Applicative (..))
import Control.Exception (Exception)
import qualified Control.Exception as E (catch)
import Control.Monad (liftM, liftM2, ap)
import Control.Monad.Fail(MonadFail(..))
import Control.Monad.Error.Class(MonadError(..))
import Control.Monad.Reader.Class(MonadReader(..))
import Control.Monad.RWS.Class(MonadRWS())
import Control.Monad.Writer.Class(MonadWriter(..), censor)
import Control.Monad.State.Class(MonadState(..))
import Control.Monad.Trans.Class (MonadTrans (lift))
import Control.Monad.IO.Unlift (MonadIO (liftIO), MonadUnliftIO, withRunInIO)
import Control.Monad.Primitive (PrimMonad, PrimState, primitive)
import Data.Functor.Identity (Identity, runIdentity)
import Data.Void (Void, absurd)
import Data.Monoid (Monoid (mappend, mempty))
import Data.Semigroup (Semigroup ((<>)))
import Control.Monad.Trans.Resource
import Data.Conduit.Internal.Pipe hiding (yield, mapOutput, leftover, yieldM, await, awaitForever, bracketP, unconsM, unconsEitherM)
import qualified Data.Conduit.Internal.Pipe as CI
import Control.Monad (forever)
import Data.Traversable (Traversable (..))

-- | Core datatype of the conduit package. This type represents a general
-- component which can consume a stream of input values @i@, produce a stream
-- of output values @o@, perform actions in the @m@ monad, and produce a final
-- result @r@. The type synonyms provided here are simply wrappers around this
-- type.
--
-- Since 1.3.0
newtype ConduitT i o m r = ConduitT
    { ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT :: forall b.
                    (r -> Pipe i i o () m b) -> Pipe i i o () m b
    }

-- | In order to provide for efficient monadic composition, the
-- @ConduitT@ type is implemented internally using a technique known
-- as the codensity transform. This allows for cheap appending, but
-- makes one case much more expensive: partially running a @ConduitT@
-- and that capturing the new state.
--
-- This data type is the same as @ConduitT@, but does not use the
-- codensity transform technique.
--
-- @since 1.3.0
newtype SealedConduitT i o m r = SealedConduitT (Pipe i i o () m r)

-- | Same as 'ConduitT', for backwards compat
type ConduitM = ConduitT

instance Functor (ConduitT i o m) where
    fmap :: (a -> b) -> ConduitT i o m a -> ConduitT i o m b
fmap a -> b
f (ConduitT forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c) = (forall b. (b -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m b
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
ConduitT ((forall b. (b -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m b)
-> (forall b. (b -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m b
forall a b. (a -> b) -> a -> b
$ \b -> Pipe i i o () m b
rest -> (a -> Pipe i i o () m b) -> Pipe i i o () m b
forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c (b -> Pipe i i o () m b
rest (b -> Pipe i i o () m b) -> (a -> b) -> a -> Pipe i i o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)

instance Applicative (ConduitT i o m) where
    pure :: a -> ConduitT i o m a
pure a
x = (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
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
ConduitT ((a -> Pipe i i o () m b) -> a -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ a
x)
    {-# INLINE pure #-}
    <*> :: ConduitT i o m (a -> b) -> ConduitT i o m a -> ConduitT i o m b
(<*>) = ConduitT i o m (a -> b) -> ConduitT i o m a -> ConduitT i o m b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
    {-# INLINE (<*>) #-}

instance Monad (ConduitT i o m) where
    return :: a -> ConduitT i o m a
return = a -> ConduitT i o m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ConduitT forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
f >>= :: ConduitT i o m a -> (a -> ConduitT i o m b) -> ConduitT i o m b
>>= a -> ConduitT i o m b
g = (forall b. (b -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m b
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
ConduitT ((forall b. (b -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m b)
-> (forall b. (b -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m b
forall a b. (a -> b) -> a -> b
$ \b -> Pipe i i o () m b
h -> (a -> Pipe i i o () m b) -> Pipe i i o () m b
forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
f ((a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> (a -> Pipe i i o () m b) -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ \a
a -> ConduitT i o m b -> (b -> Pipe i i o () m b) -> Pipe i i o () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT (a -> ConduitT i o m b
g a
a) b -> Pipe i i o () m b
h

-- | @since 1.3.1
instance MonadFail m => MonadFail (ConduitT i o m) where
    fail :: String -> ConduitT i o m a
fail = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a)
-> (String -> m a) -> String -> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
Control.Monad.Fail.fail

instance MonadThrow m => MonadThrow (ConduitT i o m) where
    throwM :: e -> ConduitT i o m a
throwM = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a) -> (e -> m a) -> e -> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM

instance MonadIO m => MonadIO (ConduitT i o m) where
    liftIO :: IO a -> ConduitT i o m a
liftIO = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a)
-> (IO a -> m a) -> IO a -> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    {-# INLINE liftIO #-}

instance MonadReader r m => MonadReader r (ConduitT i o m) where
    ask :: ConduitT i o m r
ask = m r -> ConduitT i o m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m r
forall r (m :: * -> *). MonadReader r m => m r
ask
    {-# INLINE ask #-}

    local :: (r -> r) -> ConduitT i o m a -> ConduitT i o m a
local r -> r
f (ConduitT forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c0) = (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
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
ConduitT ((forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m a)
-> (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
forall a b. (a -> b) -> a -> b
$ \a -> Pipe i i o () m b
rest ->
        let go :: Pipe i i o () m a -> Pipe i i o () m b
go (HaveOutput Pipe i i o () m a
p o
o) = Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe i i o () m a -> Pipe i i o () m b
go Pipe i i o () m a
p) o
o
            go (NeedInput i -> Pipe i i o () m a
p () -> Pipe i i o () m a
c) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput (\i
i -> Pipe i i o () m a -> Pipe i i o () m b
go (i -> Pipe i i o () m a
p i
i)) (\()
u -> Pipe i i o () m a -> Pipe i i o () m b
go (() -> Pipe i i o () m a
c ()
u))
            go (Done a
x) = a -> Pipe i i o () m b
rest a
x
            go (PipeM m (Pipe i i o () m a)
mp) = m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe i i o () m a -> Pipe i i o () m b)
-> m (Pipe i i o () m a) -> m (Pipe i i o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe i i o () m a -> Pipe i i o () m b
go (m (Pipe i i o () m a) -> m (Pipe i i o () m b))
-> m (Pipe i i o () m a) -> m (Pipe i i o () m b)
forall a b. (a -> b) -> a -> b
$ (r -> r) -> m (Pipe i i o () m a) -> m (Pipe i i o () m a)
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f m (Pipe i i o () m a)
mp)
            go (Leftover Pipe i i o () m a
p i
i) = Pipe i i o () m b -> i -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe i i o () m a -> Pipe i i o () m b
go Pipe i i o () m a
p) i
i
         in Pipe i i o () m a -> Pipe i i o () m b
go ((a -> Pipe i i o () m a) -> Pipe i i o () m a
forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c0 a -> Pipe i i o () m a
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

#ifndef MIN_VERSION_mtl
#define MIN_VERSION_mtl(x, y, z) 0
#endif

instance MonadWriter w m => MonadWriter w (ConduitT i o m) where
#if MIN_VERSION_mtl(2, 1, 0)
    writer :: (a, w) -> ConduitT i o m a
writer = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a)
-> ((a, w) -> m a) -> (a, w) -> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, w) -> m a
forall w (m :: * -> *) a. MonadWriter w m => (a, w) -> m a
writer
#endif
    tell :: w -> ConduitT i o m ()
tell = m () -> ConduitT i o m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ConduitT i o m ())
-> (w -> m ()) -> w -> ConduitT i o m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. w -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell

    listen :: ConduitT i o m a -> ConduitT i o m (a, w)
listen (ConduitT forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c0) = (forall b. ((a, w) -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m (a, w)
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
ConduitT ((forall b. ((a, w) -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m (a, w))
-> (forall b. ((a, w) -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m (a, w)
forall a b. (a -> b) -> a -> b
$ \(a, w) -> Pipe i i o () m b
rest ->
        let go :: w -> Pipe i i o () m a -> Pipe i i o () m b
go w
front (HaveOutput Pipe i i o () m a
p o
o) = Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (w -> Pipe i i o () m a -> Pipe i i o () m b
go w
front Pipe i i o () m a
p) o
o
            go w
front (NeedInput i -> Pipe i i o () m a
p () -> Pipe i i o () m a
c) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput (\i
i -> w -> Pipe i i o () m a -> Pipe i i o () m b
go w
front (i -> Pipe i i o () m a
p i
i)) (\()
u -> w -> Pipe i i o () m a -> Pipe i i o () m b
go w
front (() -> Pipe i i o () m a
c ()
u))
            go w
front (Done a
x) = (a, w) -> Pipe i i o () m b
rest (a
x, w
front)
            go w
front (PipeM m (Pipe i i o () m a)
mp) = m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i i o () m b) -> Pipe i i o () m b)
-> m (Pipe i i o () m b) -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ do
                (Pipe i i o () m a
p,w
w) <- m (Pipe i i o () m a) -> m (Pipe i i o () m a, w)
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen m (Pipe i i o () m a)
mp
                Pipe i i o () m b -> m (Pipe i i o () m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pipe i i o () m b -> m (Pipe i i o () m b))
-> Pipe i i o () m b -> m (Pipe i i o () m b)
forall a b. (a -> b) -> a -> b
$ w -> Pipe i i o () m a -> Pipe i i o () m b
go (w
front w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w) Pipe i i o () m a
p
            go w
front (Leftover Pipe i i o () m a
p i
i) = Pipe i i o () m b -> i -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (w -> Pipe i i o () m a -> Pipe i i o () m b
go w
front Pipe i i o () m a
p) i
i
         in w -> Pipe i i o () m a -> Pipe i i o () m b
go w
forall a. Monoid a => a
mempty ((a -> Pipe i i o () m a) -> Pipe i i o () m a
forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c0 a -> Pipe i i o () m a
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

    pass :: ConduitT i o m (a, w -> w) -> ConduitT i o m a
pass (ConduitT forall b. ((a, w -> w) -> Pipe i i o () m b) -> Pipe i i o () m b
c0) = (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
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
ConduitT ((forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m a)
-> (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
forall a b. (a -> b) -> a -> b
$ \a -> Pipe i i o () m b
rest ->
        let go :: w -> Pipe i i o () m (a, w -> w) -> Pipe i i o () m b
go w
front (HaveOutput Pipe i i o () m (a, w -> w)
p o
o) = Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (w -> Pipe i i o () m (a, w -> w) -> Pipe i i o () m b
go w
front Pipe i i o () m (a, w -> w)
p) o
o
            go w
front (NeedInput i -> Pipe i i o () m (a, w -> w)
p () -> Pipe i i o () m (a, w -> w)
c) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput (\i
i -> w -> Pipe i i o () m (a, w -> w) -> Pipe i i o () m b
go w
front (i -> Pipe i i o () m (a, w -> w)
p i
i)) (\()
u -> w -> Pipe i i o () m (a, w -> w) -> Pipe i i o () m b
go w
front (() -> Pipe i i o () m (a, w -> w)
c ()
u))
            go w
front (PipeM m (Pipe i i o () m (a, w -> w))
mp) = m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i i o () m b) -> Pipe i i o () m b)
-> m (Pipe i i o () m b) -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ do
                (Pipe i i o () m (a, w -> w)
p,w
w) <- (w -> w)
-> m (Pipe i i o () m (a, w -> w), w)
-> m (Pipe i i o () m (a, w -> w), w)
forall w (m :: * -> *) a. MonadWriter w m => (w -> w) -> m a -> m a
censor (w -> w -> w
forall a b. a -> b -> a
const w
forall a. Monoid a => a
mempty) (m (Pipe i i o () m (a, w -> w))
-> m (Pipe i i o () m (a, w -> w), w)
forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen m (Pipe i i o () m (a, w -> w))
mp)
                Pipe i i o () m b -> m (Pipe i i o () m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pipe i i o () m b -> m (Pipe i i o () m b))
-> Pipe i i o () m b -> m (Pipe i i o () m b)
forall a b. (a -> b) -> a -> b
$ w -> Pipe i i o () m (a, w -> w) -> Pipe i i o () m b
go (w
front w -> w -> w
forall a. Monoid a => a -> a -> a
`mappend` w
w) Pipe i i o () m (a, w -> w)
p
            go w
front (Done (a
x,w -> w
f)) = m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i i o () m b) -> Pipe i i o () m b)
-> m (Pipe i i o () m b) -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ do
                w -> m ()
forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell (w -> w
f w
front)
                Pipe i i o () m b -> m (Pipe i i o () m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pipe i i o () m b -> m (Pipe i i o () m b))
-> Pipe i i o () m b -> m (Pipe i i o () m b)
forall a b. (a -> b) -> a -> b
$ a -> Pipe i i o () m b
rest a
x
            go w
front (Leftover Pipe i i o () m (a, w -> w)
p i
i) = Pipe i i o () m b -> i -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (w -> Pipe i i o () m (a, w -> w) -> Pipe i i o () m b
go w
front Pipe i i o () m (a, w -> w)
p) i
i
         in w -> Pipe i i o () m (a, w -> w) -> Pipe i i o () m b
go w
forall a. Monoid a => a
mempty (((a, w -> w) -> Pipe i i o () m (a, w -> w))
-> Pipe i i o () m (a, w -> w)
forall b. ((a, w -> w) -> Pipe i i o () m b) -> Pipe i i o () m b
c0 (a, w -> w) -> Pipe i i o () m (a, w -> w)
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

instance MonadState s m => MonadState s (ConduitT i o m) where
    get :: ConduitT i o m s
get = m s -> ConduitT i o m s
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m s
forall s (m :: * -> *). MonadState s m => m s
get
    put :: s -> ConduitT i o m ()
put = m () -> ConduitT i o m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> ConduitT i o m ())
-> (s -> m ()) -> s -> ConduitT i o m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> m ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put
#if MIN_VERSION_mtl(2, 1, 0)
    state :: (s -> (a, s)) -> ConduitT i o m a
state = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a)
-> ((s -> (a, s)) -> m a) -> (s -> (a, s)) -> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (s -> (a, s)) -> m a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state
#endif

instance MonadRWS r w s m => MonadRWS r w s (ConduitT i o m)

instance MonadError e m => MonadError e (ConduitT i o m) where
    throwError :: e -> ConduitT i o m a
throwError = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a) -> (e -> m a) -> e -> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError
    catchError :: ConduitT i o m a -> (e -> ConduitT i o m a) -> ConduitT i o m a
catchError (ConduitT forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c0) e -> ConduitT i o m a
f = (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
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
ConduitT ((forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m a)
-> (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
forall a b. (a -> b) -> a -> b
$ \a -> Pipe i i o () m b
rest ->
        let go :: Pipe i i o () m a -> Pipe i i o () m b
go (HaveOutput Pipe i i o () m a
p o
o) = Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe i i o () m a -> Pipe i i o () m b
go Pipe i i o () m a
p) o
o
            go (NeedInput i -> Pipe i i o () m a
p () -> Pipe i i o () m a
c) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput (\i
i -> Pipe i i o () m a -> Pipe i i o () m b
go (i -> Pipe i i o () m a
p i
i)) (\()
u -> Pipe i i o () m a -> Pipe i i o () m b
go (() -> Pipe i i o () m a
c ()
u))
            go (Done a
x) = a -> Pipe i i o () m b
rest a
x
            go (PipeM m (Pipe i i o () m a)
mp) =
              m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i i o () m b) -> Pipe i i o () m b)
-> m (Pipe i i o () m b) -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ m (Pipe i i o () m b)
-> (e -> m (Pipe i i o () m b)) -> m (Pipe i i o () m b)
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
catchError ((Pipe i i o () m a -> Pipe i i o () m b)
-> m (Pipe i i o () m a) -> m (Pipe i i o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe i i o () m a -> Pipe i i o () m b
go m (Pipe i i o () m a)
mp) ((e -> m (Pipe i i o () m b)) -> m (Pipe i i o () m b))
-> (e -> m (Pipe i i o () m b)) -> m (Pipe i i o () m b)
forall a b. (a -> b) -> a -> b
$ \e
e -> do
                Pipe i i o () m b -> m (Pipe i i o () m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pipe i i o () m b -> m (Pipe i i o () m b))
-> Pipe i i o () m b -> m (Pipe i i o () m b)
forall a b. (a -> b) -> a -> b
$ ConduitT i o m a -> (a -> Pipe i i o () m b) -> Pipe i i o () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT (e -> ConduitT i o m a
f e
e) a -> Pipe i i o () m b
rest
            go (Leftover Pipe i i o () m a
p i
i) = Pipe i i o () m b -> i -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe i i o () m a -> Pipe i i o () m b
go Pipe i i o () m a
p) i
i
         in Pipe i i o () m a -> Pipe i i o () m b
go ((a -> Pipe i i o () m a) -> Pipe i i o () m a
forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b
c0 a -> Pipe i i o () m a
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

instance MonadTrans (ConduitT i o) where
    lift :: m a -> ConduitT i o m a
lift m a
mr = (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
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
ConduitT ((forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m a)
-> (forall b. (a -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m a
forall a b. (a -> b) -> a -> b
$ \a -> Pipe i i o () m b
rest -> m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((a -> Pipe i i o () m b) -> m a -> m (Pipe i i o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM a -> Pipe i i o () m b
rest m a
mr)
    {-# INLINE [1] lift #-}

instance MonadResource m => MonadResource (ConduitT i o m) where
    liftResourceT :: ResourceT IO a -> ConduitT i o m a
liftResourceT = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a)
-> (ResourceT IO a -> m a) -> ResourceT IO a -> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ResourceT IO a -> m a
forall (m :: * -> *) a. MonadResource m => ResourceT IO a -> m a
liftResourceT
    {-# INLINE liftResourceT #-}

instance Monad m => Semigroup (ConduitT i o m ()) where
    <> :: ConduitT i o m () -> ConduitT i o m () -> ConduitT i o m ()
(<>) = ConduitT i o m () -> ConduitT i o m () -> ConduitT i o m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>)
    {-# INLINE (<>) #-}

instance Monad m => Monoid (ConduitT i o m ()) where
    mempty :: ConduitT i o m ()
mempty = () -> ConduitT i o m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    {-# INLINE mempty #-}
#if !(MIN_VERSION_base(4,11,0))
    mappend = (<>)
    {-# INLINE mappend #-}
#endif

instance PrimMonad m => PrimMonad (ConduitT i o m) where
  type PrimState (ConduitT i o m) = PrimState m
  primitive :: (State# (PrimState (ConduitT i o m))
 -> (# State# (PrimState (ConduitT i o m)), a #))
-> ConduitT i o m a
primitive = m a -> ConduitT i o m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT i o m a)
-> ((State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> (State# (PrimState m) -> (# State# (PrimState m), a #))
-> ConduitT i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a
primitive

-- | Provides a stream of output values, without consuming any input or
-- producing a final result.
--
-- Since 0.5.0
type Source m o = ConduitT () o m ()
{-# DEPRECATED Source "Use ConduitT directly" #-}

-- | A component which produces a stream of output values, regardless of the
-- input stream. A @Producer@ is a generalization of a @Source@, and can be
-- used as either a @Source@ or a @Conduit@.
--
-- Since 1.0.0
type Producer m o = forall i. ConduitT i o m ()
{-# DEPRECATED Producer "Use ConduitT directly" #-}

-- | Consumes a stream of input values and produces a final result, without
-- producing any output.
--
-- > type Sink i m r = ConduitT i Void m r
--
-- Since 0.5.0
type Sink i = ConduitT i Void
{-# DEPRECATED Sink "Use ConduitT directly" #-}

-- | A component which consumes a stream of input values and produces a final
-- result, regardless of the output stream. A @Consumer@ is a generalization of
-- a @Sink@, and can be used as either a @Sink@ or a @Conduit@.
--
-- Since 1.0.0
type Consumer i m r = forall o. ConduitT i o m r
{-# DEPRECATED Consumer "Use ConduitT directly" #-}

-- | Consumes a stream of input values and produces a stream of output values,
-- without producing a final result.
--
-- Since 0.5.0
type Conduit i m o = ConduitT i o m ()
{-# DEPRECATED Conduit "Use ConduitT directly" #-}

sealConduitT :: ConduitT i o m r -> SealedConduitT i o m r
sealConduitT :: ConduitT i o m r -> SealedConduitT i o m r
sealConduitT (ConduitT forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
f) = Pipe i i o () m r -> SealedConduitT i o m r
forall i o (m :: * -> *) r.
Pipe i i o () m r -> SealedConduitT i o m r
SealedConduitT ((r -> Pipe i i o () m r) -> Pipe i i o () m r
forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
f r -> Pipe i i o () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

unsealConduitT :: Monad m => SealedConduitT i o m r -> ConduitT i o m r
unsealConduitT :: SealedConduitT i o m r -> ConduitT i o m r
unsealConduitT (SealedConduitT Pipe i i o () m r
f) = (forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
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
ConduitT (Pipe i i o () m r
f Pipe i i o () m r -> (r -> Pipe i i o () m b) -> Pipe i i o () m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=)

-- | Connect a @Source@ to a @Sink@ until the latter closes. Returns both the
-- most recent state of the @Source@ and the result of the @Sink@.
--
-- Since 0.5.0
connectResume :: Monad m
              => SealedConduitT () a m ()
              -> ConduitT a Void m r
              -> m (SealedConduitT () a m (), r)
connectResume :: SealedConduitT () a m ()
-> ConduitT a Void m r -> m (SealedConduitT () a m (), r)
connectResume (SealedConduitT Pipe () () a () m ()
left0) (ConduitT forall b. (r -> Pipe a a Void () m b) -> Pipe a a Void () m b
right0) =
    Pipe () () a () m ()
-> Pipe a a Void () m r -> m (SealedConduitT () a m (), r)
forall (m :: * -> *) i b.
Monad m =>
Pipe () () i () m ()
-> Pipe i i Void () m b -> m (SealedConduitT () i m (), b)
goRight Pipe () () a () m ()
left0 ((r -> Pipe a a Void () m r) -> Pipe a a Void () m r
forall b. (r -> Pipe a a Void () m b) -> Pipe a a Void () m b
right0 r -> Pipe a a Void () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)
  where
    goRight :: Pipe () () i () m ()
-> Pipe i i Void () m b -> m (SealedConduitT () i m (), b)
goRight Pipe () () i () m ()
left Pipe i i Void () m b
right =
        case Pipe i i Void () m b
right of
            HaveOutput Pipe i i Void () m b
_ Void
o   -> Void -> m (SealedConduitT () i m (), b)
forall a. Void -> a
absurd Void
o
            NeedInput i -> Pipe i i Void () m b
rp () -> Pipe i i Void () m b
rc  -> (i -> Pipe i i Void () m b)
-> (() -> Pipe i i Void () m b)
-> Pipe () () i () m ()
-> m (SealedConduitT () i m (), b)
goLeft i -> Pipe i i Void () m b
rp () -> Pipe i i Void () m b
rc Pipe () () i () m ()
left
            Done b
r2          -> (SealedConduitT () i m (), b) -> m (SealedConduitT () i m (), b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pipe () () i () m () -> SealedConduitT () i m ()
forall i o (m :: * -> *) r.
Pipe i i o () m r -> SealedConduitT i o m r
SealedConduitT Pipe () () i () m ()
left, b
r2)
            PipeM m (Pipe i i Void () m b)
mp         -> m (Pipe i i Void () m b)
mp m (Pipe i i Void () m b)
-> (Pipe i i Void () m b -> m (SealedConduitT () i m (), b))
-> m (SealedConduitT () i m (), b)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pipe () () i () m ()
-> Pipe i i Void () m b -> m (SealedConduitT () i m (), b)
goRight Pipe () () i () m ()
left
            Leftover Pipe i i Void () m b
p i
i     -> Pipe () () i () m ()
-> Pipe i i Void () m b -> m (SealedConduitT () i m (), b)
goRight (Pipe () () i () m () -> i -> Pipe () () i () m ()
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput Pipe () () i () m ()
left i
i) Pipe i i Void () m b
p

    goLeft :: (i -> Pipe i i Void () m b)
-> (() -> Pipe i i Void () m b)
-> Pipe () () i () m ()
-> m (SealedConduitT () i m (), b)
goLeft i -> Pipe i i Void () m b
rp () -> Pipe i i Void () m b
rc Pipe () () i () m ()
left =
        case Pipe () () i () m ()
left of
            HaveOutput Pipe () () i () m ()
left' i
o            -> Pipe () () i () m ()
-> Pipe i i Void () m b -> m (SealedConduitT () i m (), b)
goRight Pipe () () i () m ()
left' (i -> Pipe i i Void () m b
rp i
o)
            NeedInput () -> Pipe () () i () m ()
_ () -> Pipe () () i () m ()
lc                -> Pipe () () i () m () -> m (SealedConduitT () i m (), b)
recurse (() -> Pipe () () i () m ()
lc ())
            Done ()                       -> Pipe () () i () m ()
-> Pipe i i Void () m b -> m (SealedConduitT () i m (), b)
goRight (() -> Pipe () () i () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done ()) (() -> Pipe i i Void () m b
rc ())
            PipeM m (Pipe () () i () m ())
mp                      -> m (Pipe () () i () m ())
mp m (Pipe () () i () m ())
-> (Pipe () () i () m () -> m (SealedConduitT () i m (), b))
-> m (SealedConduitT () i m (), b)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pipe () () i () m () -> m (SealedConduitT () i m (), b)
recurse
            Leftover Pipe () () i () m ()
p ()                 -> Pipe () () i () m () -> m (SealedConduitT () i m (), b)
recurse Pipe () () i () m ()
p
      where
        recurse :: Pipe () () i () m () -> m (SealedConduitT () i m (), b)
recurse = (i -> Pipe i i Void () m b)
-> (() -> Pipe i i Void () m b)
-> Pipe () () i () m ()
-> m (SealedConduitT () i m (), b)
goLeft i -> Pipe i i Void () m b
rp () -> Pipe i i Void () m b
rc

sourceToPipe :: Monad m => Source m o -> Pipe l i o u m ()
sourceToPipe :: Source m o -> Pipe l i o u m ()
sourceToPipe =
    Pipe () () o () m () -> Pipe l i o u m ()
forall (m :: * -> *) i o l i u.
Monad m =>
Pipe () i o () m () -> Pipe l i o u m ()
go (Pipe () () o () m () -> Pipe l i o u m ())
-> (Source m o -> Pipe () () o () m ())
-> Source m o
-> Pipe l i o u m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Source m o -> (() -> Pipe () () o () m ()) -> Pipe () () o () m ()
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
`unConduitT` () -> Pipe () () o () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)
  where
    go :: Pipe () i o () m () -> Pipe l i o u m ()
go (HaveOutput Pipe () i o () m ()
p o
o) = Pipe l i o u m () -> o -> Pipe l i o u m ()
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe () i o () m () -> Pipe l i o u m ()
go Pipe () i o () m ()
p) o
o
    go (NeedInput i -> Pipe () i o () m ()
_ () -> Pipe () i o () m ()
c) = Pipe () i o () m () -> Pipe l i o u m ()
go (Pipe () i o () m () -> Pipe l i o u m ())
-> Pipe () i o () m () -> Pipe l i o u m ()
forall a b. (a -> b) -> a -> b
$ () -> Pipe () i o () m ()
c ()
    go (Done ()) = () -> Pipe l i o u m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done ()
    go (PipeM m (Pipe () i o () m ())
mp) = m (Pipe l i o u m ()) -> Pipe l i o u m ()
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () i o () m () -> Pipe l i o u m ())
-> m (Pipe () i o () m ()) -> m (Pipe l i o u m ())
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe () i o () m () -> Pipe l i o u m ()
go m (Pipe () i o () m ())
mp)
    go (Leftover Pipe () i o () m ()
p ()) = Pipe () i o () m () -> Pipe l i o u m ()
go Pipe () i o () m ()
p

sinkToPipe :: Monad m => Sink i m r -> Pipe l i o u m r
sinkToPipe :: Sink i m r -> Pipe l i o u m r
sinkToPipe =
    Pipe Void i Void () m r -> Pipe l i o u m r
forall (m :: * -> *) i r l o u.
Monad m =>
Pipe Void i Void () m r -> Pipe l i o u m r
go (Pipe Void i Void () m r -> Pipe l i o u m r)
-> (Sink i m r -> Pipe Void i Void () m r)
-> Sink i m r
-> Pipe l i o u m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i i Void () m r -> Pipe Void i Void () m r
forall (m :: * -> *) i o u r l.
Monad m =>
Pipe i i o u m r -> Pipe l i o u m r
injectLeftovers (Pipe i i Void () m r -> Pipe Void i Void () m r)
-> (Sink i m r -> Pipe i i Void () m r)
-> Sink i m r
-> Pipe Void i Void () m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sink i m r -> (r -> Pipe i i Void () m r) -> Pipe i i Void () m r
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
`unConduitT` r -> Pipe i i Void () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)
  where
    go :: Pipe Void i Void () m r -> Pipe l i o u m r
go (HaveOutput Pipe Void i Void () m r
_ Void
o) = Void -> Pipe l i o u m r
forall a. Void -> a
absurd Void
o
    go (NeedInput i -> Pipe Void i Void () m r
p () -> Pipe Void i Void () m r
c) = (i -> Pipe l i o u m r)
-> (u -> Pipe l i o u m r) -> Pipe l i o u m r
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
NeedInput (Pipe Void i Void () m r -> Pipe l i o u m r
go (Pipe Void i Void () m r -> Pipe l i o u m r)
-> (i -> Pipe Void i Void () m r) -> i -> Pipe l i o u m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe Void i Void () m r
p) (Pipe l i o u m r -> u -> Pipe l i o u m r
forall a b. a -> b -> a
const (Pipe l i o u m r -> u -> Pipe l i o u m r)
-> Pipe l i o u m r -> u -> Pipe l i o u m r
forall a b. (a -> b) -> a -> b
$ Pipe Void i Void () m r -> Pipe l i o u m r
go (Pipe Void i Void () m r -> Pipe l i o u m r)
-> Pipe Void i Void () m r -> Pipe l i o u m r
forall a b. (a -> b) -> a -> b
$ () -> Pipe Void i Void () m r
c ())
    go (Done r
r) = r -> Pipe l i o u m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done r
r
    go (PipeM m (Pipe Void i Void () m r)
mp) = m (Pipe l i o u m r) -> Pipe l i o u m r
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe Void i Void () m r -> Pipe l i o u m r)
-> m (Pipe Void i Void () m r) -> m (Pipe l i o u m r)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe Void i Void () m r -> Pipe l i o u m r
go m (Pipe Void i Void () m r)
mp)
    go (Leftover Pipe Void i Void () m r
_ Void
l) = Void -> Pipe l i o u m r
forall a. Void -> a
absurd Void
l

conduitToPipe :: Monad m => Conduit i m o -> Pipe l i o u m ()
conduitToPipe :: Conduit i m o -> Pipe l i o u m ()
conduitToPipe =
    Pipe Void i o () m () -> Pipe l i o u m ()
forall (m :: * -> *) i o l u.
Monad m =>
Pipe Void i o () m () -> Pipe l i o u m ()
go (Pipe Void i o () m () -> Pipe l i o u m ())
-> (Conduit i m o -> Pipe Void i o () m ())
-> Conduit i m o
-> Pipe l i o u m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pipe i i o () m () -> Pipe Void i o () m ()
forall (m :: * -> *) i o u r l.
Monad m =>
Pipe i i o u m r -> Pipe l i o u m r
injectLeftovers (Pipe i i o () m () -> Pipe Void i o () m ())
-> (Conduit i m o -> Pipe i i o () m ())
-> Conduit i m o
-> Pipe Void i o () m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Conduit i m o -> (() -> Pipe i i o () m ()) -> Pipe i i o () m ()
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
`unConduitT` () -> Pipe i i o () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)
  where
    go :: Pipe Void i o () m () -> Pipe l i o u m ()
go (HaveOutput Pipe Void i o () m ()
p o
o) = Pipe l i o u m () -> o -> Pipe l i o u m ()
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe Void i o () m () -> Pipe l i o u m ()
go Pipe Void i o () m ()
p) o
o
    go (NeedInput i -> Pipe Void i o () m ()
p () -> Pipe Void i o () m ()
c) = (i -> Pipe l i o u m ())
-> (u -> Pipe l i o u m ()) -> Pipe l i o u m ()
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
NeedInput (Pipe Void i o () m () -> Pipe l i o u m ()
go (Pipe Void i o () m () -> Pipe l i o u m ())
-> (i -> Pipe Void i o () m ()) -> i -> Pipe l i o u m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe Void i o () m ()
p) (Pipe l i o u m () -> u -> Pipe l i o u m ()
forall a b. a -> b -> a
const (Pipe l i o u m () -> u -> Pipe l i o u m ())
-> Pipe l i o u m () -> u -> Pipe l i o u m ()
forall a b. (a -> b) -> a -> b
$ Pipe Void i o () m () -> Pipe l i o u m ()
go (Pipe Void i o () m () -> Pipe l i o u m ())
-> Pipe Void i o () m () -> Pipe l i o u m ()
forall a b. (a -> b) -> a -> b
$ () -> Pipe Void i o () m ()
c ())
    go (Done ()) = () -> Pipe l i o u m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done ()
    go (PipeM m (Pipe Void i o () m ())
mp) = m (Pipe l i o u m ()) -> Pipe l i o u m ()
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe Void i o () m () -> Pipe l i o u m ())
-> m (Pipe Void i o () m ()) -> m (Pipe l i o u m ())
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe Void i o () m () -> Pipe l i o u m ()
go m (Pipe Void i o () m ())
mp)
    go (Leftover Pipe Void i o () m ()
_ Void
l) = Void -> Pipe l i o u m ()
forall a. Void -> a
absurd Void
l

-- | Generalize a 'Source' to a 'Producer'.
--
-- Since 1.0.0
toProducer :: Monad m => Source m a -> ConduitT i a m ()
toProducer :: Source m a -> ConduitT i a m ()
toProducer (ConduitT forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
c0) = (forall b. (() -> Pipe i i a () m b) -> Pipe i i a () m b)
-> ConduitT i a m ()
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
ConduitT ((forall b. (() -> Pipe i i a () m b) -> Pipe i i a () m b)
 -> ConduitT i a m ())
-> (forall b. (() -> Pipe i i a () m b) -> Pipe i i a () m b)
-> ConduitT i a m ()
forall a b. (a -> b) -> a -> b
$ \() -> Pipe i i a () m b
rest -> let
    go :: Pipe () () a () m () -> Pipe i i a () m b
go (HaveOutput Pipe () () a () m ()
p a
o) = Pipe i i a () m b -> a -> Pipe i i a () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe () () a () m () -> Pipe i i a () m b
go Pipe () () a () m ()
p) a
o
    go (NeedInput () -> Pipe () () a () m ()
_ () -> Pipe () () a () m ()
c) = Pipe () () a () m () -> Pipe i i a () m b
go (() -> Pipe () () a () m ()
c ())
    go (Done ()
r) = () -> Pipe i i a () m b
rest ()
r
    go (PipeM m (Pipe () () a () m ())
mp) = m (Pipe i i a () m b) -> Pipe i i a () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () () a () m () -> Pipe i i a () m b)
-> m (Pipe () () a () m ()) -> m (Pipe i i a () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe () () a () m () -> Pipe i i a () m b
go m (Pipe () () a () m ())
mp)
    go (Leftover Pipe () () a () m ()
p ()) = Pipe () () a () m () -> Pipe i i a () m b
go Pipe () () a () m ()
p
    in Pipe () () a () m () -> Pipe i i a () m b
go ((() -> Pipe () () a () m ()) -> Pipe () () a () m ()
forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
c0 () -> Pipe () () a () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Generalize a 'Sink' to a 'Consumer'.
--
-- Since 1.0.0
toConsumer :: Monad m => Sink a m b -> Consumer a m b
toConsumer :: Sink a m b -> Consumer a m b
toConsumer (ConduitT forall b. (b -> Pipe a a Void () m b) -> Pipe a a Void () m b
c0) = (forall b. (b -> Pipe a a o () m b) -> Pipe a a o () m b)
-> ConduitT a o m b
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
ConduitT ((forall b. (b -> Pipe a a o () m b) -> Pipe a a o () m b)
 -> ConduitT a o m b)
-> (forall b. (b -> Pipe a a o () m b) -> Pipe a a o () m b)
-> ConduitT a o m b
forall a b. (a -> b) -> a -> b
$ \b -> Pipe a a o () m b
rest -> let
    go :: Pipe a a Void () m b -> Pipe a a o () m b
go (HaveOutput Pipe a a Void () m b
_ Void
o) = Void -> Pipe a a o () m b
forall a. Void -> a
absurd Void
o
    go (NeedInput a -> Pipe a a Void () m b
p () -> Pipe a a Void () m b
c) = (a -> Pipe a a o () m b)
-> (() -> Pipe a a o () m b) -> Pipe a a o () m b
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
NeedInput (Pipe a a Void () m b -> Pipe a a o () m b
go (Pipe a a Void () m b -> Pipe a a o () m b)
-> (a -> Pipe a a Void () m b) -> a -> Pipe a a o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Pipe a a Void () m b
p) (Pipe a a Void () m b -> Pipe a a o () m b
go (Pipe a a Void () m b -> Pipe a a o () m b)
-> (() -> Pipe a a Void () m b) -> () -> Pipe a a o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe a a Void () m b
c)
    go (Done b
r) = b -> Pipe a a o () m b
rest b
r
    go (PipeM m (Pipe a a Void () m b)
mp) = m (Pipe a a o () m b) -> Pipe a a o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe a a Void () m b -> Pipe a a o () m b)
-> m (Pipe a a Void () m b) -> m (Pipe a a o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe a a Void () m b -> Pipe a a o () m b
go m (Pipe a a Void () m b)
mp)
    go (Leftover Pipe a a Void () m b
p a
l) = Pipe a a o () m b -> a -> Pipe a a o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe a a Void () m b -> Pipe a a o () m b
go Pipe a a Void () m b
p) a
l
    in Pipe a a Void () m b -> Pipe a a o () m b
go ((b -> Pipe a a Void () m b) -> Pipe a a Void () m b
forall b. (b -> Pipe a a Void () m b) -> Pipe a a Void () m b
c0 b -> Pipe a a Void () m b
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Catch all exceptions thrown by the current component of the pipeline.
--
-- Note: this will /not/ catch exceptions thrown by other components! For
-- example, if an exception is thrown in a @Source@ feeding to a @Sink@, and
-- the @Sink@ uses @catchC@, the exception will /not/ be caught.
--
-- Due to this behavior (as well as lack of async exception safety), you
-- should not try to implement combinators such as @onException@ in terms of this
-- primitive function.
--
-- Note also that the exception handling will /not/ be applied to any
-- finalizers generated by this conduit.
--
-- Since 1.0.11
catchC :: (MonadUnliftIO m, Exception e)
       => ConduitT i o m r
       -> (e -> ConduitT i o m r)
       -> ConduitT i o m r
catchC :: ConduitT i o m r -> (e -> ConduitT i o m r) -> ConduitT i o m r
catchC (ConduitT forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
p0) e -> ConduitT i o m r
onErr = (forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
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
ConduitT ((forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m r)
-> (forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i i o () m b
rest -> let
    go :: Pipe i i o () m r -> Pipe i i o () m b
go (Done r
r) = r -> Pipe i i o () m b
rest r
r
    go (PipeM m (Pipe i i o () m r)
mp) = m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i i o () m b) -> Pipe i i o () m b)
-> m (Pipe i i o () m b) -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ ((forall a. m a -> IO a) -> IO (Pipe i i o () m b))
-> m (Pipe i i o () m b)
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (((forall a. m a -> IO a) -> IO (Pipe i i o () m b))
 -> m (Pipe i i o () m b))
-> ((forall a. m a -> IO a) -> IO (Pipe i i o () m b))
-> m (Pipe i i o () m b)
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> IO (Pipe i i o () m b)
-> (e -> IO (Pipe i i o () m b)) -> IO (Pipe i i o () m b)
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
E.catch (m (Pipe i i o () m b) -> IO (Pipe i i o () m b)
forall a. m a -> IO a
run ((Pipe i i o () m r -> Pipe i i o () m b)
-> m (Pipe i i o () m r) -> m (Pipe i i o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe i i o () m r -> Pipe i i o () m b
go m (Pipe i i o () m r)
mp))
        (Pipe i i o () m b -> IO (Pipe i i o () m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Pipe i i o () m b -> IO (Pipe i i o () m b))
-> (e -> Pipe i i o () m b) -> e -> IO (Pipe i i o () m b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ConduitT i o m r -> (r -> Pipe i i o () m b) -> Pipe i i o () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
`unConduitT`r -> Pipe i i o () m b
rest) (ConduitT i o m r -> Pipe i i o () m b)
-> (e -> ConduitT i o m r) -> e -> Pipe i i o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> ConduitT i o m r
onErr)
    go (Leftover Pipe i i o () m r
p i
i) = Pipe i i o () m b -> i -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe i i o () m r -> Pipe i i o () m b
go Pipe i i o () m r
p) i
i
    go (NeedInput i -> Pipe i i o () m r
x () -> Pipe i i o () m r
y) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput (Pipe i i o () m r -> Pipe i i o () m b
go (Pipe i i o () m r -> Pipe i i o () m b)
-> (i -> Pipe i i o () m r) -> i -> Pipe i i o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe i i o () m r
x) (Pipe i i o () m r -> Pipe i i o () m b
go (Pipe i i o () m r -> Pipe i i o () m b)
-> (() -> Pipe i i o () m r) -> () -> Pipe i i o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i i o () m r
y)
    go (HaveOutput Pipe i i o () m r
p o
o) = Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe i i o () m r -> Pipe i i o () m b
go Pipe i i o () m r
p) o
o
    in Pipe i i o () m r -> Pipe i i o () m b
go ((r -> Pipe i i o () m r) -> Pipe i i o () m r
forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
p0 r -> Pipe i i o () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)
{-# INLINE catchC #-}

-- | The same as @flip catchC@.
--
-- Since 1.0.11
handleC :: (MonadUnliftIO m, Exception e)
        => (e -> ConduitT i o m r)
        -> ConduitT i o m r
        -> ConduitT i o m r
handleC :: (e -> ConduitT i o m r) -> ConduitT i o m r -> ConduitT i o m r
handleC = (ConduitT i o m r -> (e -> ConduitT i o m r) -> ConduitT i o m r)
-> (e -> ConduitT i o m r) -> ConduitT i o m r -> ConduitT i o m r
forall a b c. (a -> b -> c) -> b -> a -> c
flip ConduitT i o m r -> (e -> ConduitT i o m r) -> ConduitT i o m r
forall (m :: * -> *) e i o r.
(MonadUnliftIO m, Exception e) =>
ConduitT i o m r -> (e -> ConduitT i o m r) -> ConduitT i o m r
catchC
{-# INLINE handleC #-}

-- | A version of @try@ for use within a pipeline. See the comments in @catchC@
-- for more details.
--
-- Since 1.0.11
tryC :: (MonadUnliftIO m, Exception e)
     => ConduitT i o m r
     -> ConduitT i o m (Either e r)
tryC :: ConduitT i o m r -> ConduitT i o m (Either e r)
tryC ConduitT i o m r
c = (r -> Either e r)
-> ConduitT i o m r -> ConduitT i o m (Either e r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap r -> Either e r
forall a b. b -> Either a b
Right ConduitT i o m r
c ConduitT i o m (Either e r)
-> (e -> ConduitT i o m (Either e r))
-> ConduitT i o m (Either e r)
forall (m :: * -> *) e i o r.
(MonadUnliftIO m, Exception e) =>
ConduitT i o m r -> (e -> ConduitT i o m r) -> ConduitT i o m r
`catchC` (Either e r -> ConduitT i o m (Either e r)
forall (m :: * -> *) a. Monad m => a -> m a
return (Either e r -> ConduitT i o m (Either e r))
-> (e -> Either e r) -> e -> ConduitT i o m (Either e r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Either e r
forall a b. a -> Either a b
Left)
{-# INLINE tryC #-}

-- | Combines two sinks. The new sink will complete when both input sinks have
--   completed.
--
-- Any leftovers are discarded.
--
-- Since 0.4.1
zipSinks :: Monad m => Sink i m r -> Sink i m r' -> Sink i m (r, r')
zipSinks :: Sink i m r -> Sink i m r' -> Sink i m (r, r')
zipSinks (ConduitT forall b. (r -> Pipe i i Void () m b) -> Pipe i i Void () m b
x0) (ConduitT forall b. (r' -> Pipe i i Void () m b) -> Pipe i i Void () m b
y0) = (forall b.
 ((r, r') -> Pipe i i Void () m b) -> Pipe i i Void () m b)
-> Sink i m (r, r')
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
ConduitT ((forall b.
  ((r, r') -> Pipe i i Void () m b) -> Pipe i i Void () m b)
 -> Sink i m (r, r'))
-> (forall b.
    ((r, r') -> Pipe i i Void () m b) -> Pipe i i Void () m b)
-> Sink i m (r, r')
forall a b. (a -> b) -> a -> b
$ \(r, r') -> Pipe i i Void () m b
rest -> let
    Leftover Pipe Void i Void () m r
_  Void
i    >< :: Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< Pipe Void i Void () m r'
_                = Void -> Pipe i i Void () m b
forall a. Void -> a
absurd Void
i
    Pipe Void i Void () m r
_                >< Leftover Pipe Void i Void () m r'
_  Void
i    = Void -> Pipe i i Void () m b
forall a. Void -> a
absurd Void
i
    HaveOutput Pipe Void i Void () m r
_ Void
o   >< Pipe Void i Void () m r'
_                = Void -> Pipe i i Void () m b
forall a. Void -> a
absurd Void
o
    Pipe Void i Void () m r
_                >< HaveOutput Pipe Void i Void () m r'
_ Void
o   = Void -> Pipe i i Void () m b
forall a. Void -> a
absurd Void
o

    PipeM m (Pipe Void i Void () m r)
mx         >< Pipe Void i Void () m r'
y                = m (Pipe i i Void () m b) -> Pipe i i Void () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe Void i Void () m r -> Pipe i i Void () m b)
-> m (Pipe Void i Void () m r) -> m (Pipe i i Void () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< Pipe Void i Void () m r'
y) m (Pipe Void i Void () m r)
mx)
    Pipe Void i Void () m r
x                >< PipeM m (Pipe Void i Void () m r')
my         = m (Pipe i i Void () m b) -> Pipe i i Void () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe Void i Void () m r' -> Pipe i i Void () m b)
-> m (Pipe Void i Void () m r') -> m (Pipe i i Void () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Pipe Void i Void () m r
x Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
><) m (Pipe Void i Void () m r')
my)
    Done r
x           >< Done r'
y           = (r, r') -> Pipe i i Void () m b
rest (r
x, r'
y)
    NeedInput i -> Pipe Void i Void () m r
px () -> Pipe Void i Void () m r
cx  >< NeedInput i -> Pipe Void i Void () m r'
py () -> Pipe Void i Void () m r'
cy  = (i -> Pipe i i Void () m b)
-> (() -> Pipe i i Void () m b) -> Pipe i i Void () m b
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
NeedInput (\i
i -> i -> Pipe Void i Void () m r
px i
i Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< i -> Pipe Void i Void () m r'
py i
i) (\() -> () -> Pipe Void i Void () m r
cx () Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< () -> Pipe Void i Void () m r'
cy ())
    NeedInput i -> Pipe Void i Void () m r
px () -> Pipe Void i Void () m r
cx  >< y :: Pipe Void i Void () m r'
y@Done{}         = (i -> Pipe i i Void () m b)
-> (() -> Pipe i i Void () m b) -> Pipe i i Void () m b
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
NeedInput (\i
i -> i -> Pipe Void i Void () m r
px i
i Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< Pipe Void i Void () m r'
y)    (\()
u -> () -> Pipe Void i Void () m r
cx ()
u Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< Pipe Void i Void () m r'
y)
    x :: Pipe Void i Void () m r
x@Done{}         >< NeedInput i -> Pipe Void i Void () m r'
py () -> Pipe Void i Void () m r'
cy  = (i -> Pipe i i Void () m b)
-> (() -> Pipe i i Void () m b) -> Pipe i i Void () m b
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
NeedInput (\i
i -> Pipe Void i Void () m r
x Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< i -> Pipe Void i Void () m r'
py i
i)    (\()
u -> Pipe Void i Void () m r
x Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< () -> Pipe Void i Void () m r'
cy ()
u)
    in Pipe i i Void () m r -> Pipe Void i Void () m r
forall (m :: * -> *) i o u r l.
Monad m =>
Pipe i i o u m r -> Pipe l i o u m r
injectLeftovers ((r -> Pipe i i Void () m r) -> Pipe i i Void () m r
forall b. (r -> Pipe i i Void () m b) -> Pipe i i Void () m b
x0 r -> Pipe i i Void () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) Pipe Void i Void () m r
-> Pipe Void i Void () m r' -> Pipe i i Void () m b
>< Pipe i i Void () m r' -> Pipe Void i Void () m r'
forall (m :: * -> *) i o u r l.
Monad m =>
Pipe i i o u m r -> Pipe l i o u m r
injectLeftovers ((r' -> Pipe i i Void () m r') -> Pipe i i Void () m r'
forall b. (r' -> Pipe i i Void () m b) -> Pipe i i Void () m b
y0 r' -> Pipe i i Void () m r'
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Combines two sources. The new source will stop producing once either
--   source has been exhausted.
--
-- Since 1.0.13
zipSources :: Monad m => Source m a -> Source m b -> Source m (a, b)
zipSources :: Source m a -> Source m b -> Source m (a, b)
zipSources (ConduitT forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
left0) (ConduitT forall b. (() -> Pipe () () b () m b) -> Pipe () () b () m b
right0) = (forall b.
 (() -> Pipe () () (a, b) () m b) -> Pipe () () (a, b) () m b)
-> Source m (a, b)
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
ConduitT ((forall b.
  (() -> Pipe () () (a, b) () m b) -> Pipe () () (a, b) () m b)
 -> Source m (a, b))
-> (forall b.
    (() -> Pipe () () (a, b) () m b) -> Pipe () () (a, b) () m b)
-> Source m (a, b)
forall a b. (a -> b) -> a -> b
$ \() -> Pipe () () (a, b) () m b
rest -> let
    go :: Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go (Leftover Pipe () () a () m ()
left ()) Pipe () () b () m ()
right = Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go Pipe () () a () m ()
left Pipe () () b () m ()
right
    go Pipe () () a () m ()
left (Leftover Pipe () () b () m ()
right ())  = Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go Pipe () () a () m ()
left Pipe () () b () m ()
right
    go (Done ()) (Done ()) = () -> Pipe () () (a, b) () m b
rest ()
    go (Done ()) (HaveOutput Pipe () () b () m ()
_ b
_) = () -> Pipe () () (a, b) () m b
rest ()
    go (HaveOutput Pipe () () a () m ()
_ a
_) (Done ()) = () -> Pipe () () (a, b) () m b
rest ()
    go (Done ()) (PipeM m (Pipe () () b () m ())
_) = () -> Pipe () () (a, b) () m b
rest ()
    go (PipeM m (Pipe () () a () m ())
_) (Done ()) = () -> Pipe () () (a, b) () m b
rest ()
    go (PipeM m (Pipe () () a () m ())
mx) (PipeM m (Pipe () () b () m ())
my) = m (Pipe () () (a, b) () m b) -> Pipe () () (a, b) () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () () a () m ()
 -> Pipe () () b () m () -> Pipe () () (a, b) () m b)
-> m (Pipe () () a () m ())
-> m (Pipe () () b () m ())
-> m (Pipe () () (a, b) () m b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go m (Pipe () () a () m ())
mx m (Pipe () () b () m ())
my)
    go (PipeM m (Pipe () () a () m ())
mx) y :: Pipe () () b () m ()
y@HaveOutput{} = m (Pipe () () (a, b) () m b) -> Pipe () () (a, b) () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () () a () m () -> Pipe () () (a, b) () m b)
-> m (Pipe () () a () m ()) -> m (Pipe () () (a, b) () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\Pipe () () a () m ()
x -> Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go Pipe () () a () m ()
x Pipe () () b () m ()
y) m (Pipe () () a () m ())
mx)
    go x :: Pipe () () a () m ()
x@HaveOutput{} (PipeM m (Pipe () () b () m ())
my) = m (Pipe () () (a, b) () m b) -> Pipe () () (a, b) () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () () b () m () -> Pipe () () (a, b) () m b)
-> m (Pipe () () b () m ()) -> m (Pipe () () (a, b) () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go Pipe () () a () m ()
x) m (Pipe () () b () m ())
my)
    go (HaveOutput Pipe () () a () m ()
srcx a
x) (HaveOutput Pipe () () b () m ()
srcy b
y) = Pipe () () (a, b) () m b -> (a, b) -> Pipe () () (a, b) () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go Pipe () () a () m ()
srcx Pipe () () b () m ()
srcy) (a
x, b
y)
    go (NeedInput () -> Pipe () () a () m ()
_ () -> Pipe () () a () m ()
c) Pipe () () b () m ()
right = Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go (() -> Pipe () () a () m ()
c ()) Pipe () () b () m ()
right
    go Pipe () () a () m ()
left (NeedInput () -> Pipe () () b () m ()
_ () -> Pipe () () b () m ()
c) = Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go Pipe () () a () m ()
left (() -> Pipe () () b () m ()
c ())
    in Pipe () () a () m ()
-> Pipe () () b () m () -> Pipe () () (a, b) () m b
go ((() -> Pipe () () a () m ()) -> Pipe () () a () m ()
forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
left0 () -> Pipe () () a () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) ((() -> Pipe () () b () m ()) -> Pipe () () b () m ()
forall b. (() -> Pipe () () b () m b) -> Pipe () () b () m b
right0 () -> Pipe () () b () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Combines two sources. The new source will stop producing once either
--   source has been exhausted.
--
-- Since 1.0.13
zipSourcesApp :: Monad m => Source m (a -> b) -> Source m a -> Source m b
zipSourcesApp :: Source m (a -> b) -> Source m a -> Source m b
zipSourcesApp (ConduitT forall b.
(() -> Pipe () () (a -> b) () m b) -> Pipe () () (a -> b) () m b
left0) (ConduitT forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
right0) = (forall b. (() -> Pipe () () b () m b) -> Pipe () () b () m b)
-> Source m b
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
ConduitT ((forall b. (() -> Pipe () () b () m b) -> Pipe () () b () m b)
 -> Source m b)
-> (forall b. (() -> Pipe () () b () m b) -> Pipe () () b () m b)
-> Source m b
forall a b. (a -> b) -> a -> b
$ \() -> Pipe () () b () m b
rest -> let
    go :: Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go (Leftover Pipe () () (a -> b) () m ()
left ()) Pipe () () a () m ()
right = Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go Pipe () () (a -> b) () m ()
left Pipe () () a () m ()
right
    go Pipe () () (a -> b) () m ()
left (Leftover Pipe () () a () m ()
right ())  = Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go Pipe () () (a -> b) () m ()
left Pipe () () a () m ()
right
    go (Done ()) (Done ()) = () -> Pipe () () b () m b
rest ()
    go (Done ()) (HaveOutput Pipe () () a () m ()
_ a
_) = () -> Pipe () () b () m b
rest ()
    go (HaveOutput Pipe () () (a -> b) () m ()
_ a -> b
_) (Done ()) = () -> Pipe () () b () m b
rest ()
    go (Done ()) (PipeM m (Pipe () () a () m ())
_) = () -> Pipe () () b () m b
rest ()
    go (PipeM m (Pipe () () (a -> b) () m ())
_) (Done ()) = () -> Pipe () () b () m b
rest ()
    go (PipeM m (Pipe () () (a -> b) () m ())
mx) (PipeM m (Pipe () () a () m ())
my) = m (Pipe () () b () m b) -> Pipe () () b () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () () (a -> b) () m ()
 -> Pipe () () a () m () -> Pipe () () b () m b)
-> m (Pipe () () (a -> b) () m ())
-> m (Pipe () () a () m ())
-> m (Pipe () () b () m b)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go m (Pipe () () (a -> b) () m ())
mx m (Pipe () () a () m ())
my)
    go (PipeM m (Pipe () () (a -> b) () m ())
mx) y :: Pipe () () a () m ()
y@HaveOutput{} = m (Pipe () () b () m b) -> Pipe () () b () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () () (a -> b) () m () -> Pipe () () b () m b)
-> m (Pipe () () (a -> b) () m ()) -> m (Pipe () () b () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (\Pipe () () (a -> b) () m ()
x -> Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go Pipe () () (a -> b) () m ()
x Pipe () () a () m ()
y) m (Pipe () () (a -> b) () m ())
mx)
    go x :: Pipe () () (a -> b) () m ()
x@HaveOutput{} (PipeM m (Pipe () () a () m ())
my) = m (Pipe () () b () m b) -> Pipe () () b () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe () () a () m () -> Pipe () () b () m b)
-> m (Pipe () () a () m ()) -> m (Pipe () () b () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go Pipe () () (a -> b) () m ()
x) m (Pipe () () a () m ())
my)
    go (HaveOutput Pipe () () (a -> b) () m ()
srcx a -> b
x) (HaveOutput Pipe () () a () m ()
srcy a
y) = Pipe () () b () m b -> b -> Pipe () () b () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go Pipe () () (a -> b) () m ()
srcx Pipe () () a () m ()
srcy) (a -> b
x a
y)
    go (NeedInput () -> Pipe () () (a -> b) () m ()
_ () -> Pipe () () (a -> b) () m ()
c) Pipe () () a () m ()
right = Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go (() -> Pipe () () (a -> b) () m ()
c ()) Pipe () () a () m ()
right
    go Pipe () () (a -> b) () m ()
left (NeedInput () -> Pipe () () a () m ()
_ () -> Pipe () () a () m ()
c) = Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go Pipe () () (a -> b) () m ()
left (() -> Pipe () () a () m ()
c ())
    in Pipe () () (a -> b) () m ()
-> Pipe () () a () m () -> Pipe () () b () m b
go ((() -> Pipe () () (a -> b) () m ()) -> Pipe () () (a -> b) () m ()
forall b.
(() -> Pipe () () (a -> b) () m b) -> Pipe () () (a -> b) () m b
left0 () -> Pipe () () (a -> b) () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) ((() -> Pipe () () a () m ()) -> Pipe () () a () m ()
forall b. (() -> Pipe () () a () m b) -> Pipe () () a () m b
right0 () -> Pipe () () a () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- |
--
-- Since 1.0.17
zipConduitApp
    :: Monad m
    => ConduitT i o m (x -> y)
    -> ConduitT i o m x
    -> ConduitT i o m y
zipConduitApp :: ConduitT i o m (x -> y) -> ConduitT i o m x -> ConduitT i o m y
zipConduitApp (ConduitT forall b. ((x -> y) -> Pipe i i o () m b) -> Pipe i i o () m b
left0) (ConduitT forall b. (x -> Pipe i i o () m b) -> Pipe i i o () m b
right0) = (forall b. (y -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m y
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
ConduitT ((forall b. (y -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m y)
-> (forall b. (y -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m y
forall a b. (a -> b) -> a -> b
$ \y -> Pipe i i o () m b
rest -> let
    go :: Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go (Done x -> y
f) (Done x
x) = y -> Pipe i i o () m b
rest (x -> y
f x
x)
    go (PipeM m (Pipe Void i o () m (x -> y))
mx) Pipe Void i o () m x
y = m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe Void i o () m (x -> y)
 -> Pipe Void i o () m x -> Pipe i i o () m b)
-> Pipe Void i o () m x
-> Pipe Void i o () m (x -> y)
-> Pipe i i o () m b
forall a b c. (a -> b -> c) -> b -> a -> c
flip Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go Pipe Void i o () m x
y (Pipe Void i o () m (x -> y) -> Pipe i i o () m b)
-> m (Pipe Void i o () m (x -> y)) -> m (Pipe i i o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` m (Pipe Void i o () m (x -> y))
mx)
    go Pipe Void i o () m (x -> y)
x (PipeM m (Pipe Void i o () m x)
my) = m (Pipe i i o () m b) -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go Pipe Void i o () m (x -> y)
x (Pipe Void i o () m x -> Pipe i i o () m b)
-> m (Pipe Void i o () m x) -> m (Pipe i i o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
`liftM` m (Pipe Void i o () m x)
my)
    go (HaveOutput Pipe Void i o () m (x -> y)
x o
o) Pipe Void i o () m x
y = Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go Pipe Void i o () m (x -> y)
x Pipe Void i o () m x
y) o
o
    go Pipe Void i o () m (x -> y)
x (HaveOutput Pipe Void i o () m x
y o
o) = Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go Pipe Void i o () m (x -> y)
x Pipe Void i o () m x
y) o
o
    go (Leftover Pipe Void i o () m (x -> y)
_ Void
i) Pipe Void i o () m x
_ = Void -> Pipe i i o () m b
forall a. Void -> a
absurd Void
i
    go Pipe Void i o () m (x -> y)
_ (Leftover Pipe Void i o () m x
_ Void
i) = Void -> Pipe i i o () m b
forall a. Void -> a
absurd Void
i
    go (NeedInput i -> Pipe Void i o () m (x -> y)
px () -> Pipe Void i o () m (x -> y)
cx) (NeedInput i -> Pipe Void i o () m x
py () -> Pipe Void i o () m x
cy) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput
        (\i
i -> Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go (i -> Pipe Void i o () m (x -> y)
px i
i) (i -> Pipe Void i o () m x
py i
i))
        (\()
u -> Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go (() -> Pipe Void i o () m (x -> y)
cx ()
u) (() -> Pipe Void i o () m x
cy ()
u))
    go (NeedInput i -> Pipe Void i o () m (x -> y)
px () -> Pipe Void i o () m (x -> y)
cx) (Done x
y) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput
        (\i
i -> Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go (i -> Pipe Void i o () m (x -> y)
px i
i) (x -> Pipe Void i o () m x
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done x
y))
        (\()
u -> Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go (() -> Pipe Void i o () m (x -> y)
cx ()
u) (x -> Pipe Void i o () m x
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done x
y))
    go (Done x -> y
x) (NeedInput i -> Pipe Void i o () m x
py () -> Pipe Void i o () m x
cy) = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput
        (\i
i -> Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go ((x -> y) -> Pipe Void i o () m (x -> y)
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done x -> y
x) (i -> Pipe Void i o () m x
py i
i))
        (\()
u -> Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go ((x -> y) -> Pipe Void i o () m (x -> y)
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done x -> y
x) (() -> Pipe Void i o () m x
cy ()
u))
  in Pipe Void i o () m (x -> y)
-> Pipe Void i o () m x -> Pipe i i o () m b
go (Pipe i i o () m (x -> y) -> Pipe Void i o () m (x -> y)
forall (m :: * -> *) i o u r l.
Monad m =>
Pipe i i o u m r -> Pipe l i o u m r
injectLeftovers (Pipe i i o () m (x -> y) -> Pipe Void i o () m (x -> y))
-> Pipe i i o () m (x -> y) -> Pipe Void i o () m (x -> y)
forall a b. (a -> b) -> a -> b
$ ((x -> y) -> Pipe i i o () m (x -> y)) -> Pipe i i o () m (x -> y)
forall b. ((x -> y) -> Pipe i i o () m b) -> Pipe i i o () m b
left0 (x -> y) -> Pipe i i o () m (x -> y)
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) (Pipe i i o () m x -> Pipe Void i o () m x
forall (m :: * -> *) i o u r l.
Monad m =>
Pipe i i o u m r -> Pipe l i o u m r
injectLeftovers (Pipe i i o () m x -> Pipe Void i o () m x)
-> Pipe i i o () m x -> Pipe Void i o () m x
forall a b. (a -> b) -> a -> b
$ (x -> Pipe i i o () m x) -> Pipe i i o () m x
forall b. (x -> Pipe i i o () m b) -> Pipe i i o () m b
right0 x -> Pipe i i o () m x
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Same as normal fusion (e.g. @=$=@), except instead of discarding leftovers
-- from the downstream component, return them.
--
-- Since 1.0.17
fuseReturnLeftovers :: Monad m
                    => ConduitT a b m ()
                    -> ConduitT b c m r
                    -> ConduitT a c m (r, [b])
fuseReturnLeftovers :: ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m (r, [b])
fuseReturnLeftovers (ConduitT forall b. (() -> Pipe a a b () m b) -> Pipe a a b () m b
left0) (ConduitT forall b. (r -> Pipe b b c () m b) -> Pipe b b c () m b
right0) = (forall b. ((r, [b]) -> Pipe a a c () m b) -> Pipe a a c () m b)
-> ConduitT a c m (r, [b])
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
ConduitT ((forall b. ((r, [b]) -> Pipe a a c () m b) -> Pipe a a c () m b)
 -> ConduitT a c m (r, [b]))
-> (forall b. ((r, [b]) -> Pipe a a c () m b) -> Pipe a a c () m b)
-> ConduitT a c m (r, [b])
forall a b. (a -> b) -> a -> b
$ \(r, [b]) -> Pipe a a c () m b
rest -> let
    goRight :: [b] -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight [b]
bs Pipe a a b () m ()
left Pipe b b c () m r
right =
        case Pipe b b c () m r
right of
            HaveOutput Pipe b b c () m r
p c
o -> Pipe a a c () m b -> c -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe b b c () m r -> Pipe a a c () m b
recurse Pipe b b c () m r
p) c
o
            NeedInput b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc  ->
                case [b]
bs of
                    [] -> (b -> Pipe b b c () m r)
-> (() -> Pipe b b c () m r)
-> Pipe a a b () m ()
-> Pipe a a c () m b
goLeft b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc Pipe a a b () m ()
left
                    b
b:[b]
bs' -> [b] -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight [b]
bs' Pipe a a b () m ()
left (b -> Pipe b b c () m r
rp b
b)
            Done r
r2          -> (r, [b]) -> Pipe a a c () m b
rest (r
r2, [b]
bs)
            PipeM m (Pipe b b c () m r)
mp         -> m (Pipe a a c () m b) -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe b b c () m r -> Pipe a a c () m b)
-> m (Pipe b b c () m r) -> m (Pipe a a c () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe b b c () m r -> Pipe a a c () m b
recurse m (Pipe b b c () m r)
mp)
            Leftover Pipe b b c () m r
p b
b     -> [b] -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight (b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs) Pipe a a b () m ()
left Pipe b b c () m r
p
      where
        recurse :: Pipe b b c () m r -> Pipe a a c () m b
recurse = [b] -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight [b]
bs Pipe a a b () m ()
left

    goLeft :: (b -> Pipe b b c () m r)
-> (() -> Pipe b b c () m r)
-> Pipe a a b () m ()
-> Pipe a a c () m b
goLeft b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc Pipe a a b () m ()
left =
        case Pipe a a b () m ()
left of
            HaveOutput Pipe a a b () m ()
left' b
o        -> [b] -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight [] Pipe a a b () m ()
left' (b -> Pipe b b c () m r
rp b
o)
            NeedInput a -> Pipe a a b () m ()
left' () -> Pipe a a b () m ()
lc        -> (a -> Pipe a a c () m b)
-> (() -> Pipe a a c () m b) -> Pipe a a c () m b
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
NeedInput (Pipe a a b () m () -> Pipe a a c () m b
recurse (Pipe a a b () m () -> Pipe a a c () m b)
-> (a -> Pipe a a b () m ()) -> a -> Pipe a a c () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Pipe a a b () m ()
left') (Pipe a a b () m () -> Pipe a a c () m b
recurse (Pipe a a b () m () -> Pipe a a c () m b)
-> (() -> Pipe a a b () m ()) -> () -> Pipe a a c () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe a a b () m ()
lc)
            Done ()
r1                   -> [b] -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight [] (() -> Pipe a a b () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done ()
r1) (() -> Pipe b b c () m r
rc ()
r1)
            PipeM m (Pipe a a b () m ())
mp                  -> m (Pipe a a c () m b) -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe a a b () m () -> Pipe a a c () m b)
-> m (Pipe a a b () m ()) -> m (Pipe a a c () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe a a b () m () -> Pipe a a c () m b
recurse m (Pipe a a b () m ())
mp)
            Leftover Pipe a a b () m ()
left' a
i          -> Pipe a a c () m b -> a -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe a a b () m () -> Pipe a a c () m b
recurse Pipe a a b () m ()
left') a
i
      where
        recurse :: Pipe a a b () m () -> Pipe a a c () m b
recurse = (b -> Pipe b b c () m r)
-> (() -> Pipe b b c () m r)
-> Pipe a a b () m ()
-> Pipe a a c () m b
goLeft b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc
    in [b] -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight [] ((() -> Pipe a a b () m ()) -> Pipe a a b () m ()
forall b. (() -> Pipe a a b () m b) -> Pipe a a b () m b
left0 () -> Pipe a a b () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) ((r -> Pipe b b c () m r) -> Pipe b b c () m r
forall b. (r -> Pipe b b c () m b) -> Pipe b b c () m b
right0 r -> Pipe b b c () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Similar to @fuseReturnLeftovers@, but use the provided function to convert
-- downstream leftovers to upstream leftovers.
--
-- Since 1.0.17
fuseLeftovers
    :: Monad m
    => ([b] -> [a])
    -> ConduitT a b m ()
    -> ConduitT b c m r
    -> ConduitT a c m r
fuseLeftovers :: ([b] -> [a])
-> ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
fuseLeftovers [b] -> [a]
f ConduitT a b m ()
left ConduitT b c m r
right = do
    (r
r, [b]
bs) <- ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m (r, [b])
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m (r, [b])
fuseReturnLeftovers ConduitT a b m ()
left ConduitT b c m r
right
    (a -> ConduitT a c m ()) -> [a] -> ConduitT a c m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ a -> ConduitT a c m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover ([a] -> ConduitT a c m ()) -> [a] -> ConduitT a c m ()
forall a b. (a -> b) -> a -> b
$ [a] -> [a]
forall a. [a] -> [a]
reverse ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ [b] -> [a]
f [b]
bs
    r -> ConduitT a c m r
forall (m :: * -> *) a. Monad m => a -> m a
return r
r

-- | Connect a 'Conduit' to a sink and return the output of the sink
-- together with a new 'Conduit'.
--
-- Since 1.0.17
connectResumeConduit
    :: Monad m
    => SealedConduitT i o m ()
    -> ConduitT o Void m r
    -> ConduitT i Void m (SealedConduitT i o m (), r)
connectResumeConduit :: SealedConduitT i o m ()
-> ConduitT o Void m r
-> ConduitT i Void m (SealedConduitT i o m (), r)
connectResumeConduit (SealedConduitT Pipe i i o () m ()
left0) (ConduitT forall b. (r -> Pipe o o Void () m b) -> Pipe o o Void () m b
right0) = (forall b.
 ((SealedConduitT i o m (), r) -> Pipe i i Void () m b)
 -> Pipe i i Void () m b)
-> ConduitT i Void m (SealedConduitT i o m (), r)
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
ConduitT ((forall b.
  ((SealedConduitT i o m (), r) -> Pipe i i Void () m b)
  -> Pipe i i Void () m b)
 -> ConduitT i Void m (SealedConduitT i o m (), r))
-> (forall b.
    ((SealedConduitT i o m (), r) -> Pipe i i Void () m b)
    -> Pipe i i Void () m b)
-> ConduitT i Void m (SealedConduitT i o m (), r)
forall a b. (a -> b) -> a -> b
$ \(SealedConduitT i o m (), r) -> Pipe i i Void () m b
rest -> let
    goRight :: Pipe i i o () m () -> Pipe o o Void () m r -> Pipe i i Void () m b
goRight Pipe i i o () m ()
left Pipe o o Void () m r
right =
        case Pipe o o Void () m r
right of
            HaveOutput Pipe o o Void () m r
_ Void
o -> Void -> Pipe i i Void () m b
forall a. Void -> a
absurd Void
o
            NeedInput o -> Pipe o o Void () m r
rp () -> Pipe o o Void () m r
rc -> (o -> Pipe o o Void () m r)
-> (() -> Pipe o o Void () m r)
-> Pipe i i o () m ()
-> Pipe i i Void () m b
goLeft o -> Pipe o o Void () m r
rp () -> Pipe o o Void () m r
rc Pipe i i o () m ()
left
            Done r
r2 -> (SealedConduitT i o m (), r) -> Pipe i i Void () m b
rest (Pipe i i o () m () -> SealedConduitT i o m ()
forall i o (m :: * -> *) r.
Pipe i i o () m r -> SealedConduitT i o m r
SealedConduitT Pipe i i o () m ()
left, r
r2)
            PipeM m (Pipe o o Void () m r)
mp -> m (Pipe i i Void () m b) -> Pipe i i Void () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe o o Void () m r -> Pipe i i Void () m b)
-> m (Pipe o o Void () m r) -> m (Pipe i i Void () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Pipe i i o () m () -> Pipe o o Void () m r -> Pipe i i Void () m b
goRight Pipe i i o () m ()
left) m (Pipe o o Void () m r)
mp)
            Leftover Pipe o o Void () m r
p o
i -> Pipe i i o () m () -> Pipe o o Void () m r -> Pipe i i Void () m b
goRight (Pipe i i o () m () -> o -> Pipe i i o () m ()
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput Pipe i i o () m ()
left o
i) Pipe o o Void () m r
p

    goLeft :: (o -> Pipe o o Void () m r)
-> (() -> Pipe o o Void () m r)
-> Pipe i i o () m ()
-> Pipe i i Void () m b
goLeft o -> Pipe o o Void () m r
rp () -> Pipe o o Void () m r
rc Pipe i i o () m ()
left =
        case Pipe i i o () m ()
left of
            HaveOutput Pipe i i o () m ()
left' o
o -> Pipe i i o () m () -> Pipe o o Void () m r -> Pipe i i Void () m b
goRight Pipe i i o () m ()
left' (o -> Pipe o o Void () m r
rp o
o)
            NeedInput i -> Pipe i i o () m ()
left' () -> Pipe i i o () m ()
lc -> (i -> Pipe i i Void () m b)
-> (() -> Pipe i i Void () m b) -> Pipe i i Void () m b
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
NeedInput (Pipe i i o () m () -> Pipe i i Void () m b
recurse (Pipe i i o () m () -> Pipe i i Void () m b)
-> (i -> Pipe i i o () m ()) -> i -> Pipe i i Void () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe i i o () m ()
left') (Pipe i i o () m () -> Pipe i i Void () m b
recurse (Pipe i i o () m () -> Pipe i i Void () m b)
-> (() -> Pipe i i o () m ()) -> () -> Pipe i i Void () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i i o () m ()
lc)
            Done () -> Pipe i i o () m () -> Pipe o o Void () m r -> Pipe i i Void () m b
goRight (() -> Pipe i i o () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done ()) (() -> Pipe o o Void () m r
rc ())
            PipeM m (Pipe i i o () m ())
mp -> m (Pipe i i Void () m b) -> Pipe i i Void () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe i i o () m () -> Pipe i i Void () m b)
-> m (Pipe i i o () m ()) -> m (Pipe i i Void () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe i i o () m () -> Pipe i i Void () m b
recurse m (Pipe i i o () m ())
mp)
            Leftover Pipe i i o () m ()
left' i
i -> Pipe i i Void () m b -> i -> Pipe i i Void () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe i i o () m () -> Pipe i i Void () m b
recurse Pipe i i o () m ()
left') i
i -- recurse p
      where
        recurse :: Pipe i i o () m () -> Pipe i i Void () m b
recurse = (o -> Pipe o o Void () m r)
-> (() -> Pipe o o Void () m r)
-> Pipe i i o () m ()
-> Pipe i i Void () m b
goLeft o -> Pipe o o Void () m r
rp () -> Pipe o o Void () m r
rc
    in Pipe i i o () m () -> Pipe o o Void () m r -> Pipe i i Void () m b
goRight Pipe i i o () m ()
left0 ((r -> Pipe o o Void () m r) -> Pipe o o Void () m r
forall b. (r -> Pipe o o Void () m b) -> Pipe o o Void () m b
right0 r -> Pipe o o Void () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Merge a @Source@ into a @Conduit@.
-- The new conduit will stop processing once either source or upstream have been exhausted.
mergeSource
  :: Monad m
  => Source m i
  -> Conduit a m (i, a)
mergeSource :: Source m i -> Conduit a m (i, a)
mergeSource = SealedConduitT () i m () -> Conduit a m (i, a)
forall (m :: * -> *) i a.
Monad m =>
SealedConduitT () i m () -> Conduit a m (i, a)
loop (SealedConduitT () i m () -> Conduit a m (i, a))
-> (Source m i -> SealedConduitT () i m ())
-> Source m i
-> Conduit a m (i, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Source m i -> SealedConduitT () i m ()
forall i o (m :: * -> *) r.
ConduitT i o m r -> SealedConduitT i o m r
sealConduitT
  where
    loop :: Monad m => SealedConduitT () i m () -> Conduit a m (i, a)
    loop :: SealedConduitT () i m () -> Conduit a m (i, a)
loop SealedConduitT () i m ()
src0 = ConduitT a (i, a) m (Maybe a)
forall (m :: * -> *) i. Monad m => Consumer i m (Maybe i)
await ConduitT a (i, a) m (Maybe a)
-> (Maybe a -> Conduit a m (i, a)) -> Conduit a m (i, a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Conduit a m (i, a)
-> (a -> Conduit a m (i, a)) -> Maybe a -> Conduit a m (i, a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> Conduit a m (i, a)
forall (m :: * -> *) a. Monad m => a -> m a
return ()) a -> Conduit a m (i, a)
go
      where
        go :: a -> Conduit a m (i, a)
go a
a = do
          (SealedConduitT () i m ()
src1, Maybe i
mi) <- m (SealedConduitT () i m (), Maybe i)
-> ConduitT a (i, a) m (SealedConduitT () i m (), Maybe i)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (SealedConduitT () i m (), Maybe i)
 -> ConduitT a (i, a) m (SealedConduitT () i m (), Maybe i))
-> m (SealedConduitT () i m (), Maybe i)
-> ConduitT a (i, a) m (SealedConduitT () i m (), Maybe i)
forall a b. (a -> b) -> a -> b
$ SealedConduitT () i m ()
src0 SealedConduitT () i m ()
-> Sink i m (Maybe i) -> m (SealedConduitT () i m (), Maybe i)
forall (m :: * -> *) a b.
Monad m =>
SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
$$++ Sink i m (Maybe i)
forall (m :: * -> *) i. Monad m => Consumer i m (Maybe i)
await
          case Maybe i
mi of
            Maybe i
Nothing -> () -> Conduit a m (i, a)
forall (m :: * -> *) a. Monad m => a -> m a
return ()
            Just i
i  -> (i, a) -> Conduit a m (i, a)
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (i
i, a
a) Conduit a m (i, a) -> Conduit a m (i, a) -> Conduit a m (i, a)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> SealedConduitT () i m () -> Conduit a m (i, a)
forall (m :: * -> *) i a.
Monad m =>
SealedConduitT () i m () -> Conduit a m (i, a)
loop SealedConduitT () i m ()
src1


-- | Turn a @Sink@ into a @Conduit@ in the following way:
--
-- * All input passed to the @Sink@ is yielded downstream.
--
-- * When the @Sink@ finishes processing, the result is passed to the provided to the finalizer function.
--
-- Note that the @Sink@ will stop receiving input as soon as the downstream it
-- is connected to shuts down.
--
-- An example usage would be to write the result of a @Sink@ to some mutable
-- variable while allowing other processing to continue.
--
-- Since 1.1.0
passthroughSink :: Monad m
                => Sink i m r
                -> (r -> m ()) -- ^ finalizer
                -> Conduit i m i
passthroughSink :: Sink i m r -> (r -> m ()) -> Conduit i m i
passthroughSink (ConduitT forall b. (r -> Pipe i i Void () m b) -> Pipe i i Void () m b
sink0) r -> m ()
final = (forall b. (() -> Pipe i i i () m b) -> Pipe i i i () m b)
-> Conduit i m i
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
ConduitT ((forall b. (() -> Pipe i i i () m b) -> Pipe i i i () m b)
 -> Conduit i m i)
-> (forall b. (() -> Pipe i i i () m b) -> Pipe i i i () m b)
-> Conduit i m i
forall a b. (a -> b) -> a -> b
$ \() -> Pipe i i i () m b
rest -> let
    -- A bit of explanation is in order, this function is
    -- non-obvious. The purpose of go is to keep track of the sink
    -- we're passing values to, and then yield values downstream. The
    -- third argument to go is the current state of that sink. That's
    -- relatively straightforward.
    --
    -- The second value is the leftover buffer. These are values that
    -- the sink itself has called leftover on, and must be provided
    -- back to the sink the next time it awaits. _However_, these
    -- values should _not_ be reyielded downstream: we have already
    -- yielded them downstream ourself, and it is the responsibility
    -- of the functions wrapping around passthroughSink to handle the
    -- leftovers from downstream.
    --
    -- The trickiest bit is the first argument, which is a solution to
    -- bug https://github.com/snoyberg/conduit/issues/304. The issue
    -- is that, once we get a value, we need to provide it to both the
    -- inner sink _and_ yield it downstream. The obvious thing to do
    -- is yield first and then recursively call go. Unfortunately,
    -- this doesn't work in all cases: if the downstream component
    -- never calls await again, our yield call will never return, and
    -- our sink will not get the last value. This results is confusing
    -- behavior where the sink and downstream component receive a
    -- different number of values.
    --
    -- Solution: keep a buffer of the next value to yield downstream,
    -- and only yield it downstream in one of two cases: our sink is
    -- asking for another value, or our sink is done. This way, we
    -- ensure that, in all cases, we pass exactly the same number of
    -- values to the inner sink as to downstream.

    go :: Maybe i -> [i] -> Pipe i i Void () m r -> Pipe i i i () m b
go Maybe i
mbuf [i]
_ (Done r
r) = do
        Pipe i i i () m ()
-> (i -> Pipe i i i () m ()) -> Maybe i -> Pipe i i i () m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> Pipe i i i () m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) i -> Pipe i i i () m ()
forall (m :: * -> *) o l i u. Monad m => o -> Pipe l i o u m ()
CI.yield Maybe i
mbuf
        m () -> Pipe i i i () m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m () -> Pipe i i i () m ()) -> m () -> Pipe i i i () m ()
forall a b. (a -> b) -> a -> b
$ r -> m ()
final r
r
        Conduit i m i -> (() -> Pipe i i i () m b) -> Pipe i i i () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT ((i -> Conduit i m i) -> Conduit i m i
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever i -> Conduit i m i
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield) () -> Pipe i i i () m b
rest
    go Maybe i
mbuf [i]
is (Leftover Pipe i i Void () m r
sink i
i) = Maybe i -> [i] -> Pipe i i Void () m r -> Pipe i i i () m b
go Maybe i
mbuf (i
ii -> [i] -> [i]
forall a. a -> [a] -> [a]
:[i]
is) Pipe i i Void () m r
sink
    go Maybe i
_ [i]
_ (HaveOutput Pipe i i Void () m r
_ Void
o) = Void -> Pipe i i i () m b
forall a. Void -> a
absurd Void
o
    go Maybe i
mbuf [i]
is (PipeM m (Pipe i i Void () m r)
mx) = do
        Pipe i i Void () m r
x <- m (Pipe i i Void () m r) -> Pipe i i i () m (Pipe i i Void () m r)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m (Pipe i i Void () m r)
mx
        Maybe i -> [i] -> Pipe i i Void () m r -> Pipe i i i () m b
go Maybe i
mbuf [i]
is Pipe i i Void () m r
x
    go Maybe i
mbuf (i
i:[i]
is) (NeedInput i -> Pipe i i Void () m r
next () -> Pipe i i Void () m r
_) = Maybe i -> [i] -> Pipe i i Void () m r -> Pipe i i i () m b
go Maybe i
mbuf [i]
is (i -> Pipe i i Void () m r
next i
i)
    go Maybe i
mbuf [] (NeedInput i -> Pipe i i Void () m r
next () -> Pipe i i Void () m r
done) = do
        Pipe i i i () m ()
-> (i -> Pipe i i i () m ()) -> Maybe i -> Pipe i i i () m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> Pipe i i i () m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) i -> Pipe i i i () m ()
forall (m :: * -> *) o l i u. Monad m => o -> Pipe l i o u m ()
CI.yield Maybe i
mbuf
        Maybe i
mx <- Pipe i i i () m (Maybe i)
forall l i o u (m :: * -> *). Pipe l i o u m (Maybe i)
CI.await
        case Maybe i
mx of
            Maybe i
Nothing -> Maybe i -> [i] -> Pipe i i Void () m r -> Pipe i i i () m b
go Maybe i
forall a. Maybe a
Nothing [] (() -> Pipe i i Void () m r
done ())
            Just i
x -> Maybe i -> [i] -> Pipe i i Void () m r -> Pipe i i i () m b
go (i -> Maybe i
forall a. a -> Maybe a
Just i
x) [] (i -> Pipe i i Void () m r
next i
x)
    in Maybe i -> [i] -> Pipe i i Void () m r -> Pipe i i i () m b
go Maybe i
forall a. Maybe a
Nothing [] ((r -> Pipe i i Void () m r) -> Pipe i i Void () m r
forall b. (r -> Pipe i i Void () m b) -> Pipe i i Void () m b
sink0 r -> Pipe i i Void () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Convert a @Source@ into a list. The basic functionality can be explained as:
--
-- > sourceToList src = src $$ Data.Conduit.List.consume
--
-- However, @sourceToList@ is able to produce its results lazily, which cannot
-- be done when running a conduit pipeline in general. Unlike the
-- @Data.Conduit.Lazy@ module (in conduit-extra), this function performs no
-- unsafe I\/O operations, and therefore can only be as lazily as the
-- underlying monad.
--
-- Since 1.2.6
sourceToList :: Monad m => Source m a -> m [a]
sourceToList :: Source m a -> m [a]
sourceToList =
    Pipe () () a () m () -> m [a]
forall (m :: * -> *) l i a r. Monad m => Pipe l i a () m r -> m [a]
go (Pipe () () a () m () -> m [a])
-> (Source m a -> Pipe () () a () m ()) -> Source m a -> m [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Source m a -> (() -> Pipe () () a () m ()) -> Pipe () () a () m ()
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
`unConduitT` () -> Pipe () () a () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)
  where
    go :: Pipe l i a () m r -> m [a]
go (Done r
_) = [a] -> m [a]
forall (m :: * -> *) a. Monad m => a -> m a
return []
    go (HaveOutput Pipe l i a () m r
src a
x) = ([a] -> [a]) -> m [a] -> m [a]
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:) (Pipe l i a () m r -> m [a]
go Pipe l i a () m r
src)
    go (PipeM m (Pipe l i a () m r)
msrc) = m (Pipe l i a () m r)
msrc m (Pipe l i a () m r) -> (Pipe l i a () m r -> m [a]) -> m [a]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pipe l i a () m r -> m [a]
go
    go (NeedInput i -> Pipe l i a () m r
_ () -> Pipe l i a () m r
c) = Pipe l i a () m r -> m [a]
go (() -> Pipe l i a () m r
c ())
    go (Leftover Pipe l i a () m r
p l
_) = Pipe l i a () m r -> m [a]
go Pipe l i a () m r
p

-- Define fixity of all our operators
infixr 0 $$
infixl 1 $=
infixr 2 =$
infixr 2 =$=
infixr 0 $$+
infixr 0 $$++
infixr 0 $$+-
infixl 1 $=+
infixr 2 .|

-- | Equivalent to using 'runConduit' and '.|' together.
--
-- Since 1.2.3
connect :: Monad m
        => ConduitT () a m ()
        -> ConduitT a Void m r
        -> m r
connect :: ConduitT () a m () -> ConduitT a Void m r -> m r
connect = ConduitT () a m () -> ConduitT a Void m r -> m r
forall (m :: * -> *) a b.
Monad m =>
Source m a -> Sink a m b -> m b
($$)

-- | Split a conduit into head and tail.
--
-- Note that you have to 'sealConduitT' it first.
--
-- Since 1.3.3
unconsM :: Monad m
        => SealedConduitT () o m ()
        -> m (Maybe (o, SealedConduitT () o m ()))
unconsM :: SealedConduitT () o m () -> m (Maybe (o, SealedConduitT () o m ()))
unconsM (SealedConduitT Pipe () () o () m ()
p) = Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ()))
forall (m :: * -> *) o.
Monad m =>
Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ()))
go Pipe () () o () m ()
p
  where
    -- This function is the same as @Pipe.unconsM@ but it ignores leftovers.
    go :: Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ()))
go (HaveOutput Pipe () () o () m ()
p o
o) = Maybe (o, SealedConduitT () o m ())
-> m (Maybe (o, SealedConduitT () o m ()))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (o, SealedConduitT () o m ())
 -> m (Maybe (o, SealedConduitT () o m ())))
-> Maybe (o, SealedConduitT () o m ())
-> m (Maybe (o, SealedConduitT () o m ()))
forall a b. (a -> b) -> a -> b
$ (o, SealedConduitT () o m ())
-> Maybe (o, SealedConduitT () o m ())
forall a. a -> Maybe a
Just (o
o, Pipe () () o () m () -> SealedConduitT () o m ()
forall i o (m :: * -> *) r.
Pipe i i o () m r -> SealedConduitT i o m r
SealedConduitT Pipe () () o () m ()
p)
    go (NeedInput () -> Pipe () () o () m ()
_ () -> Pipe () () o () m ()
c) = Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ()))
go (Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ())))
-> Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ()))
forall a b. (a -> b) -> a -> b
$ () -> Pipe () () o () m ()
c ()
    go (Done ()) = Maybe (o, SealedConduitT () o m ())
-> m (Maybe (o, SealedConduitT () o m ()))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (o, SealedConduitT () o m ())
forall a. Maybe a
Nothing
    go (PipeM m (Pipe () () o () m ())
mp) = m (Pipe () () o () m ())
mp m (Pipe () () o () m ())
-> (Pipe () () o () m ()
    -> m (Maybe (o, SealedConduitT () o m ())))
-> m (Maybe (o, SealedConduitT () o m ()))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ()))
go
    go (Leftover Pipe () () o () m ()
p ()) = Pipe () () o () m () -> m (Maybe (o, SealedConduitT () o m ()))
go Pipe () () o () m ()
p

-- | 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
unconsEitherM :: Monad m
              => SealedConduitT () o m r
              -> m (Either r (o, SealedConduitT () o m r))
unconsEitherM :: SealedConduitT () o m r
-> m (Either r (o, SealedConduitT () o m r))
unconsEitherM (SealedConduitT Pipe () () o () m r
p) = Pipe () () o () m r -> m (Either r (o, SealedConduitT () o m r))
forall (m :: * -> *) o a.
Monad m =>
Pipe () () o () m a -> m (Either a (o, SealedConduitT () o m a))
go Pipe () () o () m r
p
  where
    -- This function is the same as @Pipe.unconsEitherM@ but it ignores leftovers.
    go :: Pipe () () o () m a -> m (Either a (o, SealedConduitT () o m a))
go (HaveOutput Pipe () () o () m a
p o
o) = Either a (o, SealedConduitT () o m a)
-> m (Either a (o, SealedConduitT () o m a))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either a (o, SealedConduitT () o m a)
 -> m (Either a (o, SealedConduitT () o m a)))
-> Either a (o, SealedConduitT () o m a)
-> m (Either a (o, SealedConduitT () o m a))
forall a b. (a -> b) -> a -> b
$ (o, SealedConduitT () o m a)
-> Either a (o, SealedConduitT () o m a)
forall a b. b -> Either a b
Right (o
o, Pipe () () o () m a -> SealedConduitT () o m a
forall i o (m :: * -> *) r.
Pipe i i o () m r -> SealedConduitT i o m r
SealedConduitT Pipe () () o () m a
p)
    go (NeedInput () -> Pipe () () o () m a
_ () -> Pipe () () o () m a
c) = Pipe () () o () m a -> m (Either a (o, SealedConduitT () o m a))
go (Pipe () () o () m a -> m (Either a (o, SealedConduitT () o m a)))
-> Pipe () () o () m a -> m (Either a (o, SealedConduitT () o m a))
forall a b. (a -> b) -> a -> b
$ () -> Pipe () () o () m a
c ()
    go (Done a
r) = Either a (o, SealedConduitT () o m a)
-> m (Either a (o, SealedConduitT () o m a))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either a (o, SealedConduitT () o m a)
 -> m (Either a (o, SealedConduitT () o m a)))
-> Either a (o, SealedConduitT () o m a)
-> m (Either a (o, SealedConduitT () o m a))
forall a b. (a -> b) -> a -> b
$ a -> Either a (o, SealedConduitT () o m a)
forall a b. a -> Either a b
Left a
r
    go (PipeM m (Pipe () () o () m a)
mp) = m (Pipe () () o () m a)
mp m (Pipe () () o () m a)
-> (Pipe () () o () m a
    -> m (Either a (o, SealedConduitT () o m a)))
-> m (Either a (o, SealedConduitT () o m a))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Pipe () () o () m a -> m (Either a (o, SealedConduitT () o m a))
go
    go (Leftover Pipe () () o () m a
p ()) = Pipe () () o () m a -> m (Either a (o, SealedConduitT () o m a))
go Pipe () () o () m a
p

-- | Named function synonym for '.|'
--
-- Equivalent to '.|' and '=$='. However, the latter is
-- deprecated and will be removed in a future version.
--
-- Since 1.2.3
fuse :: Monad m => Conduit a m b -> ConduitM b c m r -> ConduitM a c m r
fuse :: Conduit a m b -> ConduitM b c m r -> ConduitM a c m r
fuse = Conduit a m b -> ConduitM b c m r -> ConduitM a c m r
forall (m :: * -> *) a b c r.
Monad m =>
Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
(=$=)

-- | Combine two @Conduit@s together into a new @Conduit@ (aka 'fuse').
--
-- Output from the upstream (left) conduit will be fed into the
-- downstream (right) conduit. Processing will terminate when
-- downstream (right) returns.
-- Leftover data returned from the right @Conduit@ will be discarded.
--
-- Equivalent to 'fuse' and '=$=', however the latter is deprecated and will
-- be removed in a future version.
--
-- Note that, while this operator looks like categorical composition
-- (from "Control.Category"), there are a few reasons it's different:
--
-- * The position of the type parameters to 'ConduitT' do not
--   match. We would need to change @ConduitT i o m r@ to @ConduitT r
--   m i o@, which would preclude a 'Monad' or 'MonadTrans' instance.
--
-- * The result value from upstream and downstream are allowed to
--   differ between upstream and downstream. In other words, we would
--   need the type signature here to look like @ConduitT a b m r ->
--   ConduitT b c m r -> ConduitT a c m r@.
--
-- * Due to leftovers, we do not have a left identity in Conduit. This
--   can be achieved with the underlying @Pipe@ datatype, but this is
--   not generally recommended. See <https://stackoverflow.com/a/15263700>.
--
-- @since 1.2.8
(.|) :: Monad m
     => ConduitM a b m () -- ^ upstream
     -> ConduitM b c m r -- ^ downstream
     -> ConduitM a c m r
.| :: ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
(.|) = ConduitM a b m () -> ConduitM b c m r -> ConduitM a c m r
forall (m :: * -> *) a b c r.
Monad m =>
Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
fuse
{-# INLINE (.|) #-}

-- | The connect operator, which pulls data from a source and pushes to a sink.
-- If you would like to keep the @Source@ open to be used for other
-- operations, use the connect-and-resume operator '$$+'.
--
-- Since 0.4.0
($$) :: Monad m => Source m a -> Sink a m b -> m b
Source m a
src $$ :: Source m a -> Sink a m b -> m b
$$ Sink a m b
sink = do
    (SealedConduitT () a m ()
rsrc, b
res) <- Source m a
src Source m a -> Sink a m b -> m (SealedConduitT () a m (), b)
forall (m :: * -> *) a b.
Monad m =>
Source m a -> Sink a m b -> m (SealedConduitT () a m (), b)
$$+ Sink a m b
sink
    SealedConduitT () a m ()
rsrc SealedConduitT () a m () -> Sink a m () -> m ()
forall (m :: * -> *) a b.
Monad m =>
SealedConduitT () a m () -> Sink a m b -> m b
$$+- () -> Sink a m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
res
{-# INLINE [1] ($$) #-}
{-# DEPRECATED ($$) "Use runConduit and .|" #-}

-- | A synonym for '=$=' for backwards compatibility.
--
-- Since 0.4.0
($=) :: Monad m => Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
$= :: Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
($=) = Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
forall (m :: * -> *) a b c r.
Monad m =>
Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
(=$=)
{-# INLINE [0] ($=) #-}
{-# RULES "conduit: $= is =$=" ($=) = (=$=) #-}
{-# DEPRECATED ($=) "Use .|" #-}

-- | A synonym for '=$=' for backwards compatibility.
--
-- Since 0.4.0
(=$) :: Monad m => Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
=$ :: Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
(=$) = Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
forall (m :: * -> *) a b c r.
Monad m =>
Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
(=$=)
{-# INLINE [0] (=$) #-}
{-# RULES "conduit: =$ is =$=" (=$) = (=$=) #-}
{-# DEPRECATED (=$) "Use .|" #-}

-- | Deprecated fusion operator.
--
-- Since 0.4.0
(=$=) :: Monad m => Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
ConduitT forall b. (() -> Pipe a a b () m b) -> Pipe a a b () m b
left0 =$= :: Conduit a m b -> ConduitT b c m r -> ConduitT a c m r
=$= ConduitT forall b. (r -> Pipe b b c () m b) -> Pipe b b c () m b
right0 = (forall b. (r -> Pipe a a c () m b) -> Pipe a a c () m b)
-> ConduitT a c m r
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
ConduitT ((forall b. (r -> Pipe a a c () m b) -> Pipe a a c () m b)
 -> ConduitT a c m r)
-> (forall b. (r -> Pipe a a c () m b) -> Pipe a a c () m b)
-> ConduitT a c m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe a a c () m b
rest ->
    let goRight :: Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight Pipe a a b () m ()
left Pipe b b c () m r
right =
            case Pipe b b c () m r
right of
                HaveOutput Pipe b b c () m r
p c
o    -> Pipe a a c () m b -> c -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe b b c () m r -> Pipe a a c () m b
recurse Pipe b b c () m r
p) c
o
                NeedInput b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc   -> (b -> Pipe b b c () m r)
-> (() -> Pipe b b c () m r)
-> Pipe a a b () m ()
-> Pipe a a c () m b
goLeft b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc Pipe a a b () m ()
left
                Done r
r2           -> r -> Pipe a a c () m b
rest r
r2
                PipeM m (Pipe b b c () m r)
mp          -> m (Pipe a a c () m b) -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe b b c () m r -> Pipe a a c () m b)
-> m (Pipe b b c () m r) -> m (Pipe a a c () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe b b c () m r -> Pipe a a c () m b
recurse m (Pipe b b c () m r)
mp)
                Leftover Pipe b b c () m r
right' b
i -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight (Pipe a a b () m () -> b -> Pipe a a b () m ()
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput Pipe a a b () m ()
left b
i) Pipe b b c () m r
right'
          where
            recurse :: Pipe b b c () m r -> Pipe a a c () m b
recurse = Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight Pipe a a b () m ()
left

        goLeft :: (b -> Pipe b b c () m r)
-> (() -> Pipe b b c () m r)
-> Pipe a a b () m ()
-> Pipe a a c () m b
goLeft b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc Pipe a a b () m ()
left =
            case Pipe a a b () m ()
left of
                HaveOutput Pipe a a b () m ()
left' b
o        -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight Pipe a a b () m ()
left' (b -> Pipe b b c () m r
rp b
o)
                NeedInput a -> Pipe a a b () m ()
left' () -> Pipe a a b () m ()
lc        -> (a -> Pipe a a c () m b)
-> (() -> Pipe a a c () m b) -> Pipe a a c () m b
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
NeedInput (Pipe a a b () m () -> Pipe a a c () m b
recurse (Pipe a a b () m () -> Pipe a a c () m b)
-> (a -> Pipe a a b () m ()) -> a -> Pipe a a c () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Pipe a a b () m ()
left') (Pipe a a b () m () -> Pipe a a c () m b
recurse (Pipe a a b () m () -> Pipe a a c () m b)
-> (() -> Pipe a a b () m ()) -> () -> Pipe a a c () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe a a b () m ()
lc)
                Done ()
r1                   -> Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight (() -> Pipe a a b () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done ()
r1) (() -> Pipe b b c () m r
rc ()
r1)
                PipeM m (Pipe a a b () m ())
mp                  -> m (Pipe a a c () m b) -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe a a b () m () -> Pipe a a c () m b)
-> m (Pipe a a b () m ()) -> m (Pipe a a c () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe a a b () m () -> Pipe a a c () m b
recurse m (Pipe a a b () m ())
mp)
                Leftover Pipe a a b () m ()
left' a
i          -> Pipe a a c () m b -> a -> Pipe a a c () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe a a b () m () -> Pipe a a c () m b
recurse Pipe a a b () m ()
left') a
i
          where
            recurse :: Pipe a a b () m () -> Pipe a a c () m b
recurse = (b -> Pipe b b c () m r)
-> (() -> Pipe b b c () m r)
-> Pipe a a b () m ()
-> Pipe a a c () m b
goLeft b -> Pipe b b c () m r
rp () -> Pipe b b c () m r
rc
     in Pipe a a b () m () -> Pipe b b c () m r -> Pipe a a c () m b
goRight ((() -> Pipe a a b () m ()) -> Pipe a a b () m ()
forall b. (() -> Pipe a a b () m b) -> Pipe a a b () m b
left0 () -> Pipe a a b () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) ((r -> Pipe b b c () m r) -> Pipe b b c () m r
forall b. (r -> Pipe b b c () m b) -> Pipe b b c () m b
right0 r -> Pipe b b c () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)
{-# INLINE [1] (=$=) #-}
{-# DEPRECATED (=$=) "Use .|" #-}

-- | Wait for a single input value from upstream. If no data is available,
-- returns @Nothing@. Once @await@ returns @Nothing@, subsequent calls will
-- also return @Nothing@.
--
-- Since 0.5.0
await :: Monad m => Consumer i m (Maybe i)
await :: Consumer i m (Maybe i)
await = (forall b. (Maybe i -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m (Maybe i)
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
ConduitT ((forall b. (Maybe i -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m (Maybe i))
-> (forall b. (Maybe i -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m (Maybe i)
forall a b. (a -> b) -> a -> b
$ \Maybe i -> Pipe i i o () m b
f -> (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput (Maybe i -> Pipe i i o () m b
f (Maybe i -> Pipe i i o () m b)
-> (i -> Maybe i) -> i -> Pipe i i o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Maybe i
forall a. a -> Maybe a
Just) (Pipe i i o () m b -> () -> Pipe i i o () m b
forall a b. a -> b -> a
const (Pipe i i o () m b -> () -> Pipe i i o () m b)
-> Pipe i i o () m b -> () -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ Maybe i -> Pipe i i o () m b
f Maybe i
forall a. Maybe a
Nothing)
{-# INLINE [0] await #-}

await' :: Monad m
       => ConduitT i o m r
       -> (i -> ConduitT i o m r)
       -> ConduitT i o m r
await' :: ConduitT i o m r -> (i -> ConduitT i o m r) -> ConduitT i o m r
await' ConduitT i o m r
f i -> ConduitT i o m r
g = (forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
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
ConduitT ((forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m r)
-> (forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i i o () m b
rest -> (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput
    (\i
i -> ConduitT i o m r -> (r -> Pipe i i o () m b) -> Pipe i i o () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT (i -> ConduitT i o m r
g i
i) r -> Pipe i i o () m b
rest)
    (Pipe i i o () m b -> () -> Pipe i i o () m b
forall a b. a -> b -> a
const (Pipe i i o () m b -> () -> Pipe i i o () m b)
-> Pipe i i o () m b -> () -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ ConduitT i o m r -> (r -> Pipe i i o () m b) -> Pipe i i o () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT ConduitT i o m r
f r -> Pipe i i o () m b
rest)
{-# INLINE await' #-}
{-# RULES "conduit: await >>= maybe" forall x y. await >>= maybe x y = await' x y #-}

-- | Send a value downstream to the next component to consume. If the
-- downstream component terminates, this call will never return control.
--
-- Since 0.5.0
yield :: Monad m
      => o -- ^ output value
      -> ConduitT i o m ()
yield :: o -> ConduitT i o m ()
yield o
o = (forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m ()
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
ConduitT ((forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m ())
-> (forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m ()
forall a b. (a -> b) -> a -> b
$ \() -> Pipe i i o () m b
rest -> Pipe i i o () m b -> o -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (() -> Pipe i i o () m b
rest ()) o
o
{-# INLINE yield #-}

-- | Send a monadic value downstream for the next component to consume.
--
-- @since 1.2.7
yieldM :: Monad m => m o -> ConduitT i o m ()
yieldM :: m o -> ConduitT i o m ()
yieldM m o
mo = m o -> ConduitT i o m o
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m o
mo ConduitT i o m o -> (o -> ConduitT i o m ()) -> ConduitT i o m ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= o -> ConduitT i o m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE yieldM #-}

  -- FIXME rule won't fire, see FIXME in .Pipe; "mapM_ yield" mapM_ yield = ConduitT . sourceList

-- | Provide a single piece of leftover input to be consumed by the next
-- component in the current monadic binding.
--
-- /Note/: it is highly encouraged to only return leftover values from input
-- already consumed from upstream.
--
-- @since 0.5.0
leftover :: i -> ConduitT i o m ()
leftover :: i -> ConduitT i o m ()
leftover i
i = (forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m ()
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
ConduitT ((forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m ())
-> (forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m ()
forall a b. (a -> b) -> a -> b
$ \() -> Pipe i i o () m b
rest -> Pipe i i o () m b -> i -> Pipe i i o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (() -> Pipe i i o () m b
rest ()) i
i
{-# INLINE leftover #-}

-- | Run a pipeline until processing completes.
--
-- Since 1.2.1
runConduit :: Monad m => ConduitT () Void m r -> m r
runConduit :: ConduitT () Void m r -> m r
runConduit (ConduitT forall b. (r -> Pipe () () Void () m b) -> Pipe () () Void () m b
p) = Pipe Void () Void () m r -> m r
forall (m :: * -> *) r. Monad m => Pipe Void () Void () m r -> m r
runPipe (Pipe Void () Void () m r -> m r)
-> Pipe Void () Void () m r -> m r
forall a b. (a -> b) -> a -> b
$ Pipe () () Void () m r -> Pipe Void () Void () m r
forall (m :: * -> *) i o u r l.
Monad m =>
Pipe i i o u m r -> Pipe l i o u m r
injectLeftovers (Pipe () () Void () m r -> Pipe Void () Void () m r)
-> Pipe () () Void () m r -> Pipe Void () Void () m r
forall a b. (a -> b) -> a -> b
$ (r -> Pipe () () Void () m r) -> Pipe () () Void () m r
forall b. (r -> Pipe () () Void () m b) -> Pipe () () Void () m b
p r -> Pipe () () Void () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done
{-# INLINE [0] runConduit #-}

-- | Bracket a conduit computation between allocation and release of a
-- resource. Two guarantees are given about resource finalization:
--
-- 1. It will be /prompt/. The finalization will be run as early as possible.
--
-- 2. It is exception safe. Due to usage of @resourcet@, the finalization will
-- be run in the event of any exceptions.
--
-- Since 0.5.0
bracketP :: MonadResource m

         => IO a
            -- ^ computation to run first (\"acquire resource\")
         -> (a -> IO ())
            -- ^ computation to run last (\"release resource\")
         -> (a -> ConduitT i o m r)
            -- ^ computation to run in-between
         -> ConduitT i o m r
            -- returns the value from the in-between computation
bracketP :: IO a -> (a -> IO ()) -> (a -> ConduitT i o m r) -> ConduitT i o m r
bracketP IO a
alloc a -> IO ()
free a -> ConduitT i o m r
inside = (forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
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
ConduitT ((forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m r)
-> (forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i i o () m b
rest -> do
  (ReleaseKey
key, a
seed) <- IO a -> (a -> IO ()) -> Pipe i i o () m (ReleaseKey, a)
forall (m :: * -> *) a.
MonadResource m =>
IO a -> (a -> IO ()) -> m (ReleaseKey, a)
allocate IO a
alloc a -> IO ()
free
  ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT (a -> ConduitT i o m r
inside a
seed) ((r -> Pipe i i o () m b) -> Pipe i i o () m b)
-> (r -> Pipe i i o () m b) -> Pipe i i o () m b
forall a b. (a -> b) -> a -> b
$ \r
res -> do
    ReleaseKey -> Pipe i i o () m ()
forall (m :: * -> *). MonadIO m => ReleaseKey -> m ()
release ReleaseKey
key
    r -> Pipe i i o () m b
rest r
res

-- | Wait for input forever, calling the given inner component for each piece of
-- new input.
--
-- This function is provided as a convenience for the common pattern of
-- @await@ing input, checking if it's @Just@ and then looping.
--
-- Since 0.5.0
awaitForever :: Monad m => (i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever :: (i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever i -> ConduitT i o m r
f = (forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m ()
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
ConduitT ((forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
 -> ConduitT i o m ())
-> (forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b)
-> ConduitT i o m ()
forall a b. (a -> b) -> a -> b
$ \() -> Pipe i i o () m b
rest ->
    let go :: Pipe i i o () m b
go = (i -> Pipe i i o () m b)
-> (() -> Pipe i i o () m b) -> Pipe i i o () m b
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
NeedInput (\i
i -> ConduitT i o m r -> (r -> Pipe i i o () m b) -> Pipe i i o () m b
forall i o (m :: * -> *) r.
ConduitT i o m r
-> forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
unConduitT (i -> ConduitT i o m r
f i
i) (Pipe i i o () m b -> r -> Pipe i i o () m b
forall a b. a -> b -> a
const Pipe i i o () m b
go)) () -> Pipe i i o () m b
rest
     in Pipe i i o () m b
go

-- | Transform the monad that a @ConduitT@ lives in.
--
-- Note that the monad transforming function will be run multiple times,
-- resulting in unintuitive behavior in some cases. For a fuller treatment,
-- please see:
--
-- <https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers>
--
-- Since 0.4.0
transPipe :: Monad m => (forall a. m a -> n a) -> ConduitT i o m r -> ConduitT i o n r
transPipe :: (forall a. m a -> n a) -> ConduitT i o m r -> ConduitT i o n r
transPipe forall a. m a -> n a
f (ConduitT forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
c0) = (forall b. (r -> Pipe i i o () n b) -> Pipe i i o () n b)
-> ConduitT i o n r
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
ConduitT ((forall b. (r -> Pipe i i o () n b) -> Pipe i i o () n b)
 -> ConduitT i o n r)
-> (forall b. (r -> Pipe i i o () n b) -> Pipe i i o () n b)
-> ConduitT i o n r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i i o () n b
rest -> let
        go :: Pipe i i o () m r -> Pipe i i o () n b
go (HaveOutput Pipe i i o () m r
p o
o) = Pipe i i o () n b -> o -> Pipe i i o () n b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe i i o () m r -> Pipe i i o () n b
go Pipe i i o () m r
p) o
o
        go (NeedInput i -> Pipe i i o () m r
p () -> Pipe i i o () m r
c) = (i -> Pipe i i o () n b)
-> (() -> Pipe i i o () n b) -> Pipe i i o () n b
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
NeedInput (Pipe i i o () m r -> Pipe i i o () n b
go (Pipe i i o () m r -> Pipe i i o () n b)
-> (i -> Pipe i i o () m r) -> i -> Pipe i i o () n b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe i i o () m r
p) (Pipe i i o () m r -> Pipe i i o () n b
go (Pipe i i o () m r -> Pipe i i o () n b)
-> (() -> Pipe i i o () m r) -> () -> Pipe i i o () n b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i i o () m r
c)
        go (Done r
r) = r -> Pipe i i o () n b
rest r
r
        go (PipeM m (Pipe i i o () m r)
mp) =
            n (Pipe i i o () n b) -> Pipe i i o () n b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i i o () n b) -> n (Pipe i i o () n b)
forall a. m a -> n a
f (m (Pipe i i o () n b) -> n (Pipe i i o () n b))
-> m (Pipe i i o () n b) -> n (Pipe i i o () n b)
forall a b. (a -> b) -> a -> b
$ (Pipe i i o () m r -> Pipe i i o () n b)
-> m (Pipe i i o () m r) -> m (Pipe i i o () n b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe i i o () m r -> Pipe i i o () n b
go (m (Pipe i i o () m r) -> m (Pipe i i o () n b))
-> m (Pipe i i o () m r) -> m (Pipe i i o () n b)
forall a b. (a -> b) -> a -> b
$ m (Pipe i i o () m r) -> m (Pipe i i o () m r)
forall (m :: * -> *) l i o u r.
Monad m =>
m (Pipe l i o u m r) -> m (Pipe l i o u m r)
collapse m (Pipe i i o () m r)
mp)
          where
            -- Combine a series of monadic actions into a single action.  Since we
            -- throw away side effects between different actions, an arbitrary break
            -- between actions will lead to a violation of the monad transformer laws.
            -- Example available at:
            --
            -- http://hpaste.org/75520
            collapse :: m (Pipe l i o u m r) -> m (Pipe l i o u m r)
collapse m (Pipe l i o u m r)
mpipe = do
                Pipe l i o u m r
pipe' <- m (Pipe l i o u m r)
mpipe
                case Pipe l i o u m r
pipe' of
                    PipeM m (Pipe l i o u m r)
mpipe' -> m (Pipe l i o u m r) -> m (Pipe l i o u m r)
collapse m (Pipe l i o u m r)
mpipe'
                    Pipe l i o u m r
_ -> Pipe l i o u m r -> m (Pipe l i o u m r)
forall (m :: * -> *) a. Monad m => a -> m a
return Pipe l i o u m r
pipe'
        go (Leftover Pipe i i o () m r
p i
i) = Pipe i i o () n b -> i -> Pipe i i o () n b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe i i o () m r -> Pipe i i o () n b
go Pipe i i o () m r
p) i
i
        in Pipe i i o () m r -> Pipe i i o () n b
go ((r -> Pipe i i o () m r) -> Pipe i i o () m r
forall b. (r -> Pipe i i o () m b) -> Pipe i i o () m b
c0 r -> Pipe i i o () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Apply a function to all the output values of a @ConduitT@.
--
-- This mimics the behavior of `fmap` for a `Source` and `Conduit` in pre-0.4
-- days. It can also be simulated by fusing with the @map@ conduit from
-- "Data.Conduit.List".
--
-- Since 0.4.1
mapOutput :: Monad m => (o1 -> o2) -> ConduitT i o1 m r -> ConduitT i o2 m r
mapOutput :: (o1 -> o2) -> ConduitT i o1 m r -> ConduitT i o2 m r
mapOutput o1 -> o2
f (ConduitT forall b. (r -> Pipe i i o1 () m b) -> Pipe i i o1 () m b
c0) = (forall b. (r -> Pipe i i o2 () m b) -> Pipe i i o2 () m b)
-> ConduitT i o2 m r
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
ConduitT ((forall b. (r -> Pipe i i o2 () m b) -> Pipe i i o2 () m b)
 -> ConduitT i o2 m r)
-> (forall b. (r -> Pipe i i o2 () m b) -> Pipe i i o2 () m b)
-> ConduitT i o2 m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i i o2 () m b
rest -> let
    go :: Pipe i i o1 () m r -> Pipe i i o2 () m b
go (HaveOutput Pipe i i o1 () m r
p o1
o) = Pipe i i o2 () m b -> o2 -> Pipe i i o2 () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe i i o1 () m r -> Pipe i i o2 () m b
go Pipe i i o1 () m r
p) (o1 -> o2
f o1
o)
    go (NeedInput i -> Pipe i i o1 () m r
p () -> Pipe i i o1 () m r
c) = (i -> Pipe i i o2 () m b)
-> (() -> Pipe i i o2 () m b) -> Pipe i i o2 () m b
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
NeedInput (Pipe i i o1 () m r -> Pipe i i o2 () m b
go (Pipe i i o1 () m r -> Pipe i i o2 () m b)
-> (i -> Pipe i i o1 () m r) -> i -> Pipe i i o2 () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe i i o1 () m r
p) (Pipe i i o1 () m r -> Pipe i i o2 () m b
go (Pipe i i o1 () m r -> Pipe i i o2 () m b)
-> (() -> Pipe i i o1 () m r) -> () -> Pipe i i o2 () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i i o1 () m r
c)
    go (Done r
r) = r -> Pipe i i o2 () m b
rest r
r
    go (PipeM m (Pipe i i o1 () m r)
mp) = m (Pipe i i o2 () m b) -> Pipe i i o2 () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe i i o1 () m r -> Pipe i i o2 () m b)
-> m (Pipe i i o1 () m r) -> m (Pipe i i o2 () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Pipe i i o1 () m r -> Pipe i i o2 () m b
go) m (Pipe i i o1 () m r)
mp)
    go (Leftover Pipe i i o1 () m r
p i
i) = Pipe i i o2 () m b -> i -> Pipe i i o2 () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe i i o1 () m r -> Pipe i i o2 () m b
go Pipe i i o1 () m r
p) i
i
    in Pipe i i o1 () m r -> Pipe i i o2 () m b
go ((r -> Pipe i i o1 () m r) -> Pipe i i o1 () m r
forall b. (r -> Pipe i i o1 () m b) -> Pipe i i o1 () m b
c0 r -> Pipe i i o1 () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Same as 'mapOutput', but use a function that returns @Maybe@ values.
--
-- Since 0.5.0
mapOutputMaybe :: Monad m => (o1 -> Maybe o2) -> ConduitT i o1 m r -> ConduitT i o2 m r
mapOutputMaybe :: (o1 -> Maybe o2) -> ConduitT i o1 m r -> ConduitT i o2 m r
mapOutputMaybe o1 -> Maybe o2
f (ConduitT forall b. (r -> Pipe i i o1 () m b) -> Pipe i i o1 () m b
c0) = (forall b. (r -> Pipe i i o2 () m b) -> Pipe i i o2 () m b)
-> ConduitT i o2 m r
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
ConduitT ((forall b. (r -> Pipe i i o2 () m b) -> Pipe i i o2 () m b)
 -> ConduitT i o2 m r)
-> (forall b. (r -> Pipe i i o2 () m b) -> Pipe i i o2 () m b)
-> ConduitT i o2 m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i i o2 () m b
rest -> let
    go :: Pipe i i o1 () m r -> Pipe i i o2 () m b
go (HaveOutput Pipe i i o1 () m r
p o1
o) = (Pipe i i o2 () m b -> Pipe i i o2 () m b)
-> (o2 -> Pipe i i o2 () m b -> Pipe i i o2 () m b)
-> Maybe o2
-> Pipe i i o2 () m b
-> Pipe i i o2 () m b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Pipe i i o2 () m b -> Pipe i i o2 () m b
forall a. a -> a
id (\o2
o' Pipe i i o2 () m b
p' -> Pipe i i o2 () m b -> o2 -> Pipe i i o2 () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput Pipe i i o2 () m b
p' o2
o') (o1 -> Maybe o2
f o1
o) (Pipe i i o1 () m r -> Pipe i i o2 () m b
go Pipe i i o1 () m r
p)
    go (NeedInput i -> Pipe i i o1 () m r
p () -> Pipe i i o1 () m r
c) = (i -> Pipe i i o2 () m b)
-> (() -> Pipe i i o2 () m b) -> Pipe i i o2 () m b
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
NeedInput (Pipe i i o1 () m r -> Pipe i i o2 () m b
go (Pipe i i o1 () m r -> Pipe i i o2 () m b)
-> (i -> Pipe i i o1 () m r) -> i -> Pipe i i o2 () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i -> Pipe i i o1 () m r
p) (Pipe i i o1 () m r -> Pipe i i o2 () m b
go (Pipe i i o1 () m r -> Pipe i i o2 () m b)
-> (() -> Pipe i i o1 () m r) -> () -> Pipe i i o2 () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i i o1 () m r
c)
    go (Done r
r) = r -> Pipe i i o2 () m b
rest r
r
    go (PipeM m (Pipe i i o1 () m r)
mp) = m (Pipe i i o2 () m b) -> Pipe i i o2 () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM ((Pipe i i o1 () m r -> Pipe i i o2 () m b)
-> m (Pipe i i o1 () m r) -> m (Pipe i i o2 () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Pipe i i o1 () m r -> Pipe i i o2 () m b
go) m (Pipe i i o1 () m r)
mp)
    go (Leftover Pipe i i o1 () m r
p i
i) = Pipe i i o2 () m b -> i -> Pipe i i o2 () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Pipe i i o1 () m r -> Pipe i i o2 () m b
go Pipe i i o1 () m r
p) i
i
    in Pipe i i o1 () m r -> Pipe i i o2 () m b
go ((r -> Pipe i i o1 () m r) -> Pipe i i o1 () m r
forall b. (r -> Pipe i i o1 () m b) -> Pipe i i o1 () m b
c0 r -> Pipe i i o1 () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Apply a function to all the input values of a @ConduitT@.
--
-- Since 0.5.0
mapInput :: Monad m
         => (i1 -> i2) -- ^ map initial input to new input
         -> (i2 -> Maybe i1) -- ^ map new leftovers to initial leftovers
         -> ConduitT i2 o m r
         -> ConduitT i1 o m r
mapInput :: (i1 -> i2)
-> (i2 -> Maybe i1) -> ConduitT i2 o m r -> ConduitT i1 o m r
mapInput i1 -> i2
f i2 -> Maybe i1
f' (ConduitT forall b. (r -> Pipe i2 i2 o () m b) -> Pipe i2 i2 o () m b
c0) = (forall b. (r -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> ConduitT i1 o m r
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
ConduitT ((forall b. (r -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
 -> ConduitT i1 o m r)
-> (forall b. (r -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> ConduitT i1 o m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i1 i1 o () m b
rest -> let
    go :: Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go (HaveOutput Pipe i2 i2 o () m r
p o
o) = Pipe i1 i1 o () m b -> o -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go Pipe i2 i2 o () m r
p) o
o
    go (NeedInput i2 -> Pipe i2 i2 o () m r
p () -> Pipe i2 i2 o () m r
c) = (i1 -> Pipe i1 i1 o () m b)
-> (() -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
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
NeedInput (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b)
-> (i1 -> Pipe i2 i2 o () m r) -> i1 -> Pipe i1 i1 o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i2 -> Pipe i2 i2 o () m r
p (i2 -> Pipe i2 i2 o () m r)
-> (i1 -> i2) -> i1 -> Pipe i2 i2 o () m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i1 -> i2
f) (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b)
-> (() -> Pipe i2 i2 o () m r) -> () -> Pipe i1 i1 o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i2 i2 o () m r
c)
    go (Done r
r) = r -> Pipe i1 i1 o () m b
rest r
r
    go (PipeM m (Pipe i2 i2 o () m r)
mp) = m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall a b. (a -> b) -> a -> b
$ (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b)
-> m (Pipe i2 i2 o () m r) -> m (Pipe i1 i1 o () m b)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go m (Pipe i2 i2 o () m r)
mp
    go (Leftover Pipe i2 i2 o () m r
p i2
i) = (Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b)
-> (i1 -> Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b)
-> Maybe i1
-> Pipe i1 i1 o () m b
-> Pipe i1 i1 o () m b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b
forall a. a -> a
id ((Pipe i1 i1 o () m b -> i1 -> Pipe i1 i1 o () m b)
-> i1 -> Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b
forall a b c. (a -> b -> c) -> b -> a -> c
flip Pipe i1 i1 o () m b -> i1 -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover) (i2 -> Maybe i1
f' i2
i) (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go Pipe i2 i2 o () m r
p)
    in Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go ((r -> Pipe i2 i2 o () m r) -> Pipe i2 i2 o () m r
forall b. (r -> Pipe i2 i2 o () m b) -> Pipe i2 i2 o () m b
c0 r -> Pipe i2 i2 o () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Apply a monadic action to all the input values of a @ConduitT@.
--
-- Since 1.3.2
mapInputM :: Monad m
          => (i1 -> m i2) -- ^ map initial input to new input
          -> (i2 -> m (Maybe i1)) -- ^ map new leftovers to initial leftovers
          -> ConduitT i2 o m r
          -> ConduitT i1 o m r
mapInputM :: (i1 -> m i2)
-> (i2 -> m (Maybe i1)) -> ConduitT i2 o m r -> ConduitT i1 o m r
mapInputM i1 -> m i2
f i2 -> m (Maybe i1)
f' (ConduitT forall b. (r -> Pipe i2 i2 o () m b) -> Pipe i2 i2 o () m b
c0) = (forall b. (r -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> ConduitT i1 o m r
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
ConduitT ((forall b. (r -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
 -> ConduitT i1 o m r)
-> (forall b. (r -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> ConduitT i1 o m r
forall a b. (a -> b) -> a -> b
$ \r -> Pipe i1 i1 o () m b
rest -> let
    go :: Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go (HaveOutput Pipe i2 i2 o () m r
p o
o) = Pipe i1 i1 o () m b -> o -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go Pipe i2 i2 o () m r
p) o
o
    go (NeedInput i2 -> Pipe i2 i2 o () m r
p () -> Pipe i2 i2 o () m r
c)  = (i1 -> Pipe i1 i1 o () m b)
-> (() -> Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
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
NeedInput (\i1
i -> m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall a b. (a -> b) -> a -> b
$ Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b)
-> (i2 -> Pipe i2 i2 o () m r) -> i2 -> Pipe i1 i1 o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. i2 -> Pipe i2 i2 o () m r
p (i2 -> Pipe i1 i1 o () m b) -> m i2 -> m (Pipe i1 i1 o () m b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> i1 -> m i2
f i1
i) (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b)
-> (() -> Pipe i2 i2 o () m r) -> () -> Pipe i1 i1 o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Pipe i2 i2 o () m r
c)
    go (Done r
r)         = r -> Pipe i1 i1 o () m b
rest r
r
    go (PipeM m (Pipe i2 i2 o () m r)
mp)       = m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall a b. (a -> b) -> a -> b
$ (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b)
-> m (Pipe i2 i2 o () m r) -> m (Pipe i1 i1 o () m b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go m (Pipe i2 i2 o () m r)
mp
    go (Leftover Pipe i2 i2 o () m r
p i2
i)   = m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b)
-> m (Pipe i1 i1 o () m b) -> Pipe i1 i1 o () m b
forall a b. (a -> b) -> a -> b
$ (\Maybe i1
x -> (Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b)
-> (i1 -> Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b)
-> Maybe i1
-> Pipe i1 i1 o () m b
-> Pipe i1 i1 o () m b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b
forall a. a -> a
id ((Pipe i1 i1 o () m b -> i1 -> Pipe i1 i1 o () m b)
-> i1 -> Pipe i1 i1 o () m b -> Pipe i1 i1 o () m b
forall a b c. (a -> b -> c) -> b -> a -> c
flip Pipe i1 i1 o () m b -> i1 -> Pipe i1 i1 o () m b
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover) Maybe i1
x (Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go Pipe i2 i2 o () m r
p)) (Maybe i1 -> Pipe i1 i1 o () m b)
-> m (Maybe i1) -> m (Pipe i1 i1 o () m b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> i2 -> m (Maybe i1)
f' i2
i
    in Pipe i2 i2 o () m r -> Pipe i1 i1 o () m b
go ((r -> Pipe i2 i2 o () m r) -> Pipe i2 i2 o () m r
forall b. (r -> Pipe i2 i2 o () m b) -> Pipe i2 i2 o () m b
c0 r -> Pipe i2 i2 o () m r
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | The connect-and-resume operator. This does not close the @Source@, but
-- instead returns it to be used again. This allows a @Source@ to be used
-- incrementally in a large program, without forcing the entire program to live
-- in the @Sink@ monad.
--
-- Mnemonic: connect + do more.
--
-- Since 0.5.0
($$+) :: Monad m => Source m a -> Sink a m b -> m (SealedConduitT () a m (), b)
Source m a
src $$+ :: Source m a -> Sink a m b -> m (SealedConduitT () a m (), b)
$$+ Sink a m b
sink = SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
forall (m :: * -> *) a b.
Monad m =>
SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
connectResume (Source m a -> SealedConduitT () a m ()
forall i o (m :: * -> *) r.
ConduitT i o m r -> SealedConduitT i o m r
sealConduitT Source m a
src) Sink a m b
sink
{-# INLINE ($$+) #-}

-- | Continue processing after usage of @$$+@.
--
-- Since 0.5.0
($$++) :: Monad m => SealedConduitT () a m () -> Sink a m b -> m (SealedConduitT () a m (), b)
$$++ :: SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
($$++) = SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
forall (m :: * -> *) a b.
Monad m =>
SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
connectResume
{-# INLINE ($$++) #-}

-- | Same as @$$++@ and @connectResume@, but doesn't include the
-- updated @SealedConduitT@.
--
-- /NOTE/ In previous versions, this would cause finalizers to
-- run. Since version 1.3.0, there are no finalizers in conduit.
--
-- Since 0.5.0
($$+-) :: Monad m => SealedConduitT () a m () -> Sink a m b -> m b
SealedConduitT () a m ()
rsrc $$+- :: SealedConduitT () a m () -> Sink a m b -> m b
$$+- Sink a m b
sink = do
    (SealedConduitT () a m ()
_, b
res) <- SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
forall (m :: * -> *) a b.
Monad m =>
SealedConduitT () a m ()
-> Sink a m b -> m (SealedConduitT () a m (), b)
connectResume SealedConduitT () a m ()
rsrc Sink a m b
sink
    b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
res
{-# INLINE ($$+-) #-}

-- | Left fusion for a sealed source.
--
-- Since 1.0.16
($=+) :: Monad m => SealedConduitT () a m () -> Conduit a m b -> SealedConduitT () b m ()
SealedConduitT Pipe () () a () m ()
src $=+ :: SealedConduitT () a m ()
-> Conduit a m b -> SealedConduitT () b m ()
$=+ ConduitT forall b. (() -> Pipe a a b () m b) -> Pipe a a b () m b
sink = Pipe () () b () m () -> SealedConduitT () b m ()
forall i o (m :: * -> *) r.
Pipe i i o () m r -> SealedConduitT i o m r
SealedConduitT (Pipe () () a () m ()
src Pipe () () a () m () -> Pipe a a b () m () -> Pipe () () b () m ()
forall (m :: * -> *) l a b r0 r1 c r2.
Monad m =>
Pipe l a b r0 m r1 -> Pipe b b c r1 m r2 -> Pipe l a c r0 m r2
`pipeL` (() -> Pipe a a b () m ()) -> Pipe a a b () m ()
forall b. (() -> Pipe a a b () m b) -> Pipe a a b () m b
sink () -> Pipe a a b () m ()
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done)

-- | Provide for a stream of data that can be flushed.
--
-- A number of @Conduit@s (e.g., zlib compression) need the ability to flush
-- the stream at some point. This provides a single wrapper datatype to be used
-- in all such circumstances.
--
-- Since 0.3.0
data Flush a = Chunk a | Flush
    deriving (Int -> Flush a -> ShowS
[Flush a] -> ShowS
Flush a -> String
(Int -> Flush a -> ShowS)
-> (Flush a -> String) -> ([Flush a] -> ShowS) -> Show (Flush a)
forall a. Show a => Int -> Flush a -> ShowS
forall a. Show a => [Flush a] -> ShowS
forall a. Show a => Flush a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Flush a] -> ShowS
$cshowList :: forall a. Show a => [Flush a] -> ShowS
show :: Flush a -> String
$cshow :: forall a. Show a => Flush a -> String
showsPrec :: Int -> Flush a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Flush a -> ShowS
Show, Flush a -> Flush a -> Bool
(Flush a -> Flush a -> Bool)
-> (Flush a -> Flush a -> Bool) -> Eq (Flush a)
forall a. Eq a => Flush a -> Flush a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Flush a -> Flush a -> Bool
$c/= :: forall a. Eq a => Flush a -> Flush a -> Bool
== :: Flush a -> Flush a -> Bool
$c== :: forall a. Eq a => Flush a -> Flush a -> Bool
Eq, Eq (Flush a)
Eq (Flush a)
-> (Flush a -> Flush a -> Ordering)
-> (Flush a -> Flush a -> Bool)
-> (Flush a -> Flush a -> Bool)
-> (Flush a -> Flush a -> Bool)
-> (Flush a -> Flush a -> Bool)
-> (Flush a -> Flush a -> Flush a)
-> (Flush a -> Flush a -> Flush a)
-> Ord (Flush a)
Flush a -> Flush a -> Bool
Flush a -> Flush a -> Ordering
Flush a -> Flush a -> Flush a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Flush a)
forall a. Ord a => Flush a -> Flush a -> Bool
forall a. Ord a => Flush a -> Flush a -> Ordering
forall a. Ord a => Flush a -> Flush a -> Flush a
min :: Flush a -> Flush a -> Flush a
$cmin :: forall a. Ord a => Flush a -> Flush a -> Flush a
max :: Flush a -> Flush a -> Flush a
$cmax :: forall a. Ord a => Flush a -> Flush a -> Flush a
>= :: Flush a -> Flush a -> Bool
$c>= :: forall a. Ord a => Flush a -> Flush a -> Bool
> :: Flush a -> Flush a -> Bool
$c> :: forall a. Ord a => Flush a -> Flush a -> Bool
<= :: Flush a -> Flush a -> Bool
$c<= :: forall a. Ord a => Flush a -> Flush a -> Bool
< :: Flush a -> Flush a -> Bool
$c< :: forall a. Ord a => Flush a -> Flush a -> Bool
compare :: Flush a -> Flush a -> Ordering
$ccompare :: forall a. Ord a => Flush a -> Flush a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (Flush a)
Ord)
instance Functor Flush where
    fmap :: (a -> b) -> Flush a -> Flush b
fmap a -> b
_ Flush a
Flush = Flush b
forall a. Flush a
Flush
    fmap a -> b
f (Chunk a
a) = b -> Flush b
forall a. a -> Flush a
Chunk (a -> b
f a
a)

-- | A wrapper for defining an 'Applicative' instance for 'Source's which allows
-- to combine sources together, generalizing 'zipSources'. A combined source
-- will take input yielded from each of its @Source@s until any of them stop
-- producing output.
--
-- Since 1.0.13
newtype ZipSource m o = ZipSource { ZipSource m o -> Source m o
getZipSource :: Source m o }

instance Monad m => Functor (ZipSource m) where
    fmap :: (a -> b) -> ZipSource m a -> ZipSource m b
fmap a -> b
f = Source m b -> ZipSource m b
forall (m :: * -> *) o. Source m o -> ZipSource m o
ZipSource (Source m b -> ZipSource m b)
-> (ZipSource m a -> Source m b) -> ZipSource m a -> ZipSource m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> ConduitT () a m () -> Source m b
forall (m :: * -> *) o1 o2 i r.
Monad m =>
(o1 -> o2) -> ConduitT i o1 m r -> ConduitT i o2 m r
mapOutput a -> b
f (ConduitT () a m () -> Source m b)
-> (ZipSource m a -> ConduitT () a m ())
-> ZipSource m a
-> Source m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZipSource m a -> ConduitT () a m ()
forall (m :: * -> *) o. ZipSource m o -> Source m o
getZipSource
instance Monad m => Applicative (ZipSource m) where
    pure :: a -> ZipSource m a
pure  = Source m a -> ZipSource m a
forall (m :: * -> *) o. Source m o -> ZipSource m o
ZipSource (Source m a -> ZipSource m a)
-> (a -> Source m a) -> a -> ZipSource m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Source m a -> Source m a
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (Source m a -> Source m a) -> (a -> Source m a) -> a -> Source m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Source m a
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
    (ZipSource Source m (a -> b)
f) <*> :: ZipSource m (a -> b) -> ZipSource m a -> ZipSource m b
<*> (ZipSource Source m a
x) = Source m b -> ZipSource m b
forall (m :: * -> *) o. Source m o -> ZipSource m o
ZipSource (Source m b -> ZipSource m b) -> Source m b -> ZipSource m b
forall a b. (a -> b) -> a -> b
$ Source m (a -> b) -> Source m a -> Source m b
forall (m :: * -> *) a b.
Monad m =>
Source m (a -> b) -> Source m a -> Source m b
zipSourcesApp Source m (a -> b)
f Source m a
x

-- | Coalesce all values yielded by all of the @Source@s.
--
-- Implemented on top of @ZipSource@ and as such, it exhibits the same
-- short-circuiting behavior as @ZipSource@. See that data type for more
-- details. If you want to create a source that yields *all* values from
-- multiple sources, use `sequence_`.
--
-- Since 1.0.13
sequenceSources :: (Traversable f, Monad m) => f (Source m o) -> Source m (f o)
sequenceSources :: f (Source m o) -> Source m (f o)
sequenceSources = ZipSource m (f o) -> Source m (f o)
forall (m :: * -> *) o. ZipSource m o -> Source m o
getZipSource (ZipSource m (f o) -> Source m (f o))
-> (f (Source m o) -> ZipSource m (f o))
-> f (Source m o)
-> Source m (f o)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (ZipSource m o) -> ZipSource m (f o)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA (f (ZipSource m o) -> ZipSource m (f o))
-> (f (Source m o) -> f (ZipSource m o))
-> f (Source m o)
-> ZipSource m (f o)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Source m o -> ZipSource m o)
-> f (Source m o) -> f (ZipSource m o)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Source m o -> ZipSource m o
forall (m :: * -> *) o. Source m o -> ZipSource m o
ZipSource

-- | A wrapper for defining an 'Applicative' instance for 'Sink's which allows
-- to combine sinks together, generalizing 'zipSinks'. A combined sink
-- distributes the input to all its participants and when all finish, produces
-- the result. This allows to define functions like
--
-- @
-- sequenceSinks :: (Monad m)
--           => [Sink i m r] -> Sink i m [r]
-- sequenceSinks = getZipSink . sequenceA . fmap ZipSink
-- @
--
-- Note that the standard 'Applicative' instance for conduits works
-- differently. It feeds one sink with input until it finishes, then switches
-- to another, etc., and at the end combines their results.
--
-- This newtype is in fact a type constrained version of 'ZipConduit', and has
-- the same behavior. It's presented as a separate type since (1) it
-- historically predates @ZipConduit@, and (2) the type constraining can make
-- your code clearer (and thereby make your error messages more easily
-- understood).
--
-- Since 1.0.13
newtype ZipSink i m r = ZipSink { ZipSink i m r -> Sink i m r
getZipSink :: Sink i m r }

instance Monad m => Functor (ZipSink i m) where
    fmap :: (a -> b) -> ZipSink i m a -> ZipSink i m b
fmap a -> b
f (ZipSink Sink i m a
x) = Sink i m b -> ZipSink i m b
forall i (m :: * -> *) r. Sink i m r -> ZipSink i m r
ZipSink ((a -> b) -> Sink i m a -> Sink i m b
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM a -> b
f Sink i m a
x)
instance Monad m => Applicative (ZipSink i m) where
    pure :: a -> ZipSink i m a
pure  = Sink i m a -> ZipSink i m a
forall i (m :: * -> *) r. Sink i m r -> ZipSink i m r
ZipSink (Sink i m a -> ZipSink i m a)
-> (a -> Sink i m a) -> a -> ZipSink i m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Sink i m a
forall (m :: * -> *) a. Monad m => a -> m a
return
    (ZipSink Sink i m (a -> b)
f) <*> :: ZipSink i m (a -> b) -> ZipSink i m a -> ZipSink i m b
<*> (ZipSink Sink i m a
x) =
         Sink i m b -> ZipSink i m b
forall i (m :: * -> *) r. Sink i m r -> ZipSink i m r
ZipSink (Sink i m b -> ZipSink i m b) -> Sink i m b -> ZipSink i m b
forall a b. (a -> b) -> a -> b
$ ((a -> b, a) -> b) -> ConduitT i Void m (a -> b, a) -> Sink i m b
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (((a -> b) -> a -> b) -> (a -> b, a) -> b
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (a -> b) -> a -> b
forall a b. (a -> b) -> a -> b
($)) (ConduitT i Void m (a -> b, a) -> Sink i m b)
-> ConduitT i Void m (a -> b, a) -> Sink i m b
forall a b. (a -> b) -> a -> b
$ Sink i m (a -> b) -> Sink i m a -> ConduitT i Void m (a -> b, a)
forall (m :: * -> *) i r r'.
Monad m =>
Sink i m r -> Sink i m r' -> Sink i m (r, r')
zipSinks Sink i m (a -> b)
f Sink i m a
x

-- | Send incoming values to all of the @Sink@ providing, and ultimately
-- coalesce together all return values.
--
-- Implemented on top of @ZipSink@, see that data type for more details.
--
-- Since 1.0.13
sequenceSinks :: (Traversable f, Monad m) => f (Sink i m r) -> Sink i m (f r)
sequenceSinks :: f (Sink i m r) -> Sink i m (f r)
sequenceSinks = ZipSink i m (f r) -> Sink i m (f r)
forall i (m :: * -> *) r. ZipSink i m r -> Sink i m r
getZipSink (ZipSink i m (f r) -> Sink i m (f r))
-> (f (Sink i m r) -> ZipSink i m (f r))
-> f (Sink i m r)
-> Sink i m (f r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (ZipSink i m r) -> ZipSink i m (f r)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA (f (ZipSink i m r) -> ZipSink i m (f r))
-> (f (Sink i m r) -> f (ZipSink i m r))
-> f (Sink i m r)
-> ZipSink i m (f r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sink i m r -> ZipSink i m r)
-> f (Sink i m r) -> f (ZipSink i m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Sink i m r -> ZipSink i m r
forall i (m :: * -> *) r. Sink i m r -> ZipSink i m r
ZipSink

-- | The connect-and-resume operator. This does not close the @Conduit@, but
-- instead returns it to be used again. This allows a @Conduit@ to be used
-- incrementally in a large program, without forcing the entire program to live
-- in the @Sink@ monad.
--
-- Leftover data returned from the @Sink@ will be discarded.
--
-- Mnemonic: connect + do more.
--
-- Since 1.0.17
(=$$+) :: Monad m
       => ConduitT a b m ()
       -> ConduitT b Void m r
       -> ConduitT a Void m (SealedConduitT a b m (), r)
=$$+ :: ConduitT a b m ()
-> ConduitT b Void m r
-> ConduitT a Void m (SealedConduitT a b m (), r)
(=$$+) ConduitT a b m ()
conduit = SealedConduitT a b m ()
-> ConduitT b Void m r
-> ConduitT a Void m (SealedConduitT a b m (), r)
forall (m :: * -> *) i o r.
Monad m =>
SealedConduitT i o m ()
-> ConduitT o Void m r
-> ConduitT i Void m (SealedConduitT i o m (), r)
connectResumeConduit (ConduitT a b m () -> SealedConduitT a b m ()
forall i o (m :: * -> *) r.
ConduitT i o m r -> SealedConduitT i o m r
sealConduitT ConduitT a b m ()
conduit)
{-# INLINE (=$$+) #-}

-- | Continue processing after usage of '=$$+'. Connect a 'SealedConduitT' to
-- a sink and return the output of the sink together with a new
-- 'SealedConduitT'.
--
-- Since 1.0.17
(=$$++) :: Monad m => SealedConduitT i o m () -> ConduitT o Void m r -> ConduitT i Void m (SealedConduitT i o m (), r)
=$$++ :: SealedConduitT i o m ()
-> ConduitT o Void m r
-> ConduitT i Void m (SealedConduitT i o m (), r)
(=$$++) = SealedConduitT i o m ()
-> ConduitT o Void m r
-> ConduitT i Void m (SealedConduitT i o m (), r)
forall (m :: * -> *) i o r.
Monad m =>
SealedConduitT i o m ()
-> ConduitT o Void m r
-> ConduitT i Void m (SealedConduitT i o m (), r)
connectResumeConduit
{-# INLINE (=$$++) #-}

-- | Same as @=$$++@, but doesn't include the updated
-- @SealedConduitT@.
--
-- /NOTE/ In previous versions, this would cause finalizers to
-- run. Since version 1.3.0, there are no finalizers in conduit.
--
-- Since 1.0.17
(=$$+-) :: Monad m => SealedConduitT i o m () -> ConduitT o Void m r -> ConduitT i Void m r
SealedConduitT i o m ()
rsrc =$$+- :: SealedConduitT i o m ()
-> ConduitT o Void m r -> ConduitT i Void m r
=$$+- ConduitT o Void m r
sink = do
    (SealedConduitT i o m ()
_, r
res) <- SealedConduitT i o m ()
-> ConduitT o Void m r
-> ConduitT i Void m (SealedConduitT i o m (), r)
forall (m :: * -> *) i o r.
Monad m =>
SealedConduitT i o m ()
-> ConduitT o Void m r
-> ConduitT i Void m (SealedConduitT i o m (), r)
connectResumeConduit SealedConduitT i o m ()
rsrc ConduitT o Void m r
sink
    r -> ConduitT i Void m r
forall (m :: * -> *) a. Monad m => a -> m a
return r
res
{-# INLINE (=$$+-) #-}


infixr 0 =$$+
infixr 0 =$$++
infixr 0 =$$+-

-- | Provides an alternative @Applicative@ instance for @ConduitT@. In this instance,
-- every incoming value is provided to all @ConduitT@s, and output is coalesced together.
-- Leftovers from individual @ConduitT@s will be used within that component, and then discarded
-- at the end of their computation. Output and finalizers will both be handled in a left-biased manner.
--
-- As an example, take the following program:
--
-- @
-- main :: IO ()
-- main = do
--     let src = mapM_ yield [1..3 :: Int]
--         conduit1 = CL.map (+1)
--         conduit2 = CL.concatMap (replicate 2)
--         conduit = getZipConduit $ ZipConduit conduit1 <* ZipConduit conduit2
--         sink = CL.mapM_ print
--     src $$ conduit =$ sink
-- @
--
-- It will produce the output: 2, 1, 1, 3, 2, 2, 4, 3, 3
--
-- Since 1.0.17
newtype ZipConduit i o m r = ZipConduit { ZipConduit i o m r -> ConduitT i o m r
getZipConduit :: ConduitT i o m r }
    deriving a -> ZipConduit i o m b -> ZipConduit i o m a
(a -> b) -> ZipConduit i o m a -> ZipConduit i o m b
(forall a b. (a -> b) -> ZipConduit i o m a -> ZipConduit i o m b)
-> (forall a b. a -> ZipConduit i o m b -> ZipConduit i o m a)
-> Functor (ZipConduit i o m)
forall a b. a -> ZipConduit i o m b -> ZipConduit i o m a
forall a b. (a -> b) -> ZipConduit i o m a -> ZipConduit i o m b
forall i o (m :: * -> *) a b.
a -> ZipConduit i o m b -> ZipConduit i o m a
forall i o (m :: * -> *) a b.
(a -> b) -> ZipConduit i o m a -> ZipConduit i o m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ZipConduit i o m b -> ZipConduit i o m a
$c<$ :: forall i o (m :: * -> *) a b.
a -> ZipConduit i o m b -> ZipConduit i o m a
fmap :: (a -> b) -> ZipConduit i o m a -> ZipConduit i o m b
$cfmap :: forall i o (m :: * -> *) a b.
(a -> b) -> ZipConduit i o m a -> ZipConduit i o m b
Functor
instance Monad m => Applicative (ZipConduit i o m) where
    pure :: a -> ZipConduit i o m a
pure = ConduitT i o m a -> ZipConduit i o m a
forall i o (m :: * -> *) r. ConduitT i o m r -> ZipConduit i o m r
ZipConduit (ConduitT i o m a -> ZipConduit i o m a)
-> (a -> ConduitT i o m a) -> a -> ZipConduit i o m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> ConduitT i o m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ZipConduit ConduitT i o m (a -> b)
left <*> :: ZipConduit i o m (a -> b)
-> ZipConduit i o m a -> ZipConduit i o m b
<*> ZipConduit ConduitT i o m a
right = ConduitT i o m b -> ZipConduit i o m b
forall i o (m :: * -> *) r. ConduitT i o m r -> ZipConduit i o m r
ZipConduit (ConduitT i o m (a -> b) -> ConduitT i o m a -> ConduitT i o m b
forall (m :: * -> *) i o x y.
Monad m =>
ConduitT i o m (x -> y) -> ConduitT i o m x -> ConduitT i o m y
zipConduitApp ConduitT i o m (a -> b)
left ConduitT i o m a
right)

-- | Provide identical input to all of the @Conduit@s and combine their outputs
-- into a single stream.
--
-- Implemented on top of @ZipConduit@, see that data type for more details.
--
-- Since 1.0.17
sequenceConduits :: (Traversable f, Monad m) => f (ConduitT i o m r) -> ConduitT i o m (f r)
sequenceConduits :: f (ConduitT i o m r) -> ConduitT i o m (f r)
sequenceConduits = ZipConduit i o m (f r) -> ConduitT i o m (f r)
forall i o (m :: * -> *) r. ZipConduit i o m r -> ConduitT i o m r
getZipConduit (ZipConduit i o m (f r) -> ConduitT i o m (f r))
-> (f (ConduitT i o m r) -> ZipConduit i o m (f r))
-> f (ConduitT i o m r)
-> ConduitT i o m (f r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (ZipConduit i o m r) -> ZipConduit i o m (f r)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA (f (ZipConduit i o m r) -> ZipConduit i o m (f r))
-> (f (ConduitT i o m r) -> f (ZipConduit i o m r))
-> f (ConduitT i o m r)
-> ZipConduit i o m (f r)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ConduitT i o m r -> ZipConduit i o m r)
-> f (ConduitT i o m r) -> f (ZipConduit i o m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConduitT i o m r -> ZipConduit i o m r
forall i o (m :: * -> *) r. ConduitT i o m r -> ZipConduit i o m r
ZipConduit

-- | Fuse two @ConduitT@s together, and provide the return value of both. Note
-- that this will force the entire upstream @ConduitT@ to be run to produce the
-- result value, even if the downstream terminates early.
--
-- Since 1.1.5
fuseBoth :: Monad m => ConduitT a b m r1 -> ConduitT b c m r2 -> ConduitT a c m (r1, r2)
fuseBoth :: ConduitT a b m r1 -> ConduitT b c m r2 -> ConduitT a c m (r1, r2)
fuseBoth (ConduitT forall b. (r1 -> Pipe a a b () m b) -> Pipe a a b () m b
up) (ConduitT forall b. (r2 -> Pipe b b c () m b) -> Pipe b b c () m b
down) =
    (forall b. ((r1, r2) -> Pipe a a c () m b) -> Pipe a a c () m b)
-> ConduitT a c m (r1, r2)
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
ConduitT (Pipe a a b () m r1
-> Pipe b b c r1 m (r1, r2) -> Pipe a a c () m (r1, r2)
forall (m :: * -> *) l a b r0 r1 c r2.
Monad m =>
Pipe l a b r0 m r1 -> Pipe b b c r1 m r2 -> Pipe l a c r0 m r2
pipeL ((r1 -> Pipe a a b () m r1) -> Pipe a a b () m r1
forall b. (r1 -> Pipe a a b () m b) -> Pipe a a b () m b
up r1 -> Pipe a a b () m r1
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) (Pipe b b c r1 m r2 -> Pipe b b c r1 m (r1, r2)
forall (m :: * -> *) l i o u r.
Monad m =>
Pipe l i o u m r -> Pipe l i o u m (u, r)
withUpstream (Pipe b b c r1 m r2 -> Pipe b b c r1 m (r1, r2))
-> Pipe b b c r1 m r2 -> Pipe b b c r1 m (r1, r2)
forall a b. (a -> b) -> a -> b
$ Pipe b b c () m r2 -> Pipe b b c r1 m r2
forall (m :: * -> *) l i o r u.
Monad m =>
Pipe l i o () m r -> Pipe l i o u m r
generalizeUpstream (Pipe b b c () m r2 -> Pipe b b c r1 m r2)
-> Pipe b b c () m r2 -> Pipe b b c r1 m r2
forall a b. (a -> b) -> a -> b
$ (r2 -> Pipe b b c () m r2) -> Pipe b b c () m r2
forall b. (r2 -> Pipe b b c () m b) -> Pipe b b c () m b
down r2 -> Pipe b b c () m r2
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) Pipe a a c () m (r1, r2)
-> ((r1, r2) -> Pipe a a c () m b) -> Pipe a a c () m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=)
{-# INLINE fuseBoth #-}

-- | Like 'fuseBoth', but does not force consumption of the @Producer@.
-- In the case that the @Producer@ terminates, the result value is
-- provided as a @Just@ value. If it does not terminate, then a
-- @Nothing@ value is returned.
--
-- One thing to note here is that "termination" here only occurs if the
-- @Producer@ actually yields a @Nothing@ value. For example, with the
-- @Producer@ @mapM_ yield [1..5]@, if five values are requested, the
-- @Producer@ has not yet terminated. Termination only occurs when the
-- sixth value is awaited for and the @Producer@ signals termination.
--
-- Since 1.2.4
fuseBothMaybe
    :: Monad m
    => ConduitT a b m r1
    -> ConduitT b c m r2
    -> ConduitT a c m (Maybe r1, r2)
fuseBothMaybe :: ConduitT a b m r1
-> ConduitT b c m r2 -> ConduitT a c m (Maybe r1, r2)
fuseBothMaybe (ConduitT forall b. (r1 -> Pipe a a b () m b) -> Pipe a a b () m b
up) (ConduitT forall b. (r2 -> Pipe b b c () m b) -> Pipe b b c () m b
down) =
    (forall b.
 ((Maybe r1, r2) -> Pipe a a c () m b) -> Pipe a a c () m b)
-> ConduitT a c m (Maybe r1, r2)
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
ConduitT (Pipe a a b () m r1
-> Pipe b b c r1 m (Maybe r1, r2) -> Pipe a a c () m (Maybe r1, r2)
forall (m :: * -> *) l a b r0 r1 c r2.
Monad m =>
Pipe l a b r0 m r1 -> Pipe b b c r1 m r2 -> Pipe l a c r0 m r2
pipeL ((r1 -> Pipe a a b () m r1) -> Pipe a a b () m r1
forall b. (r1 -> Pipe a a b () m b) -> Pipe a a b () m b
up r1 -> Pipe a a b () m r1
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) (Maybe r1 -> Pipe b b c () m r2 -> Pipe b b c r1 m (Maybe r1, r2)
forall (m :: * -> *) u l i o b.
Monad m =>
Maybe u -> Pipe l i o () m b -> Pipe l i o u m (Maybe u, b)
go Maybe r1
forall a. Maybe a
Nothing (Pipe b b c () m r2 -> Pipe b b c r1 m (Maybe r1, r2))
-> Pipe b b c () m r2 -> Pipe b b c r1 m (Maybe r1, r2)
forall a b. (a -> b) -> a -> b
$ (r2 -> Pipe b b c () m r2) -> Pipe b b c () m r2
forall b. (r2 -> Pipe b b c () m b) -> Pipe b b c () m b
down r2 -> Pipe b b c () m r2
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done) Pipe a a c () m (Maybe r1, r2)
-> ((Maybe r1, r2) -> Pipe a a c () m b) -> Pipe a a c () m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=)
  where
    go :: Maybe u -> Pipe l i o () m b -> Pipe l i o u m (Maybe u, b)
go Maybe u
mup (Done b
r) = (Maybe u, b) -> Pipe l i o u m (Maybe u, b)
forall l i o u (m :: * -> *) r. r -> Pipe l i o u m r
Done (Maybe u
mup, b
r)
    go Maybe u
mup (PipeM m (Pipe l i o () m b)
mp) = m (Pipe l i o u m (Maybe u, b)) -> Pipe l i o u m (Maybe u, b)
forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (m (Pipe l i o u m (Maybe u, b)) -> Pipe l i o u m (Maybe u, b))
-> m (Pipe l i o u m (Maybe u, b)) -> Pipe l i o u m (Maybe u, b)
forall a b. (a -> b) -> a -> b
$ (Pipe l i o () m b -> Pipe l i o u m (Maybe u, b))
-> m (Pipe l i o () m b) -> m (Pipe l i o u m (Maybe u, b))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Maybe u -> Pipe l i o () m b -> Pipe l i o u m (Maybe u, b)
go Maybe u
mup) m (Pipe l i o () m b)
mp
    go Maybe u
mup (HaveOutput Pipe l i o () m b
p o
o) = Pipe l i o u m (Maybe u, b) -> o -> Pipe l i o u m (Maybe u, b)
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> o -> Pipe l i o u m r
HaveOutput (Maybe u -> Pipe l i o () m b -> Pipe l i o u m (Maybe u, b)
go Maybe u
mup Pipe l i o () m b
p) o
o
    go Maybe u
_ (NeedInput i -> Pipe l i o () m b
p () -> Pipe l i o () m b
c) = (i -> Pipe l i o u m (Maybe u, b))
-> (u -> Pipe l i o u m (Maybe u, b))
-> Pipe l i o u m (Maybe u, b)
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
NeedInput
        (\i
i -> Maybe u -> Pipe l i o () m b -> Pipe l i o u m (Maybe u, b)
go Maybe u
forall a. Maybe a
Nothing (i -> Pipe l i o () m b
p i
i))
        (\u
u -> Maybe u -> Pipe l i o () m b -> Pipe l i o u m (Maybe u, b)
go (u -> Maybe u
forall a. a -> Maybe a
Just u
u) (() -> Pipe l i o () m b
c ()))
    go Maybe u
mup (Leftover Pipe l i o () m b
p l
i) = Pipe l i o u m (Maybe u, b) -> l -> Pipe l i o u m (Maybe u, b)
forall l i o u (m :: * -> *) r.
Pipe l i o u m r -> l -> Pipe l i o u m r
Leftover (Maybe u -> Pipe l i o () m b -> Pipe l i o u m (Maybe u, b)
go Maybe u
mup Pipe l i o () m b
p) l
i
{-# INLINABLE fuseBothMaybe #-}

-- | Same as @fuseBoth@, but ignore the return value from the downstream
-- @Conduit@. Same caveats of forced consumption apply.
--
-- Since 1.1.5
fuseUpstream :: Monad m => ConduitT a b m r -> Conduit b m c -> ConduitT a c m r
fuseUpstream :: ConduitT a b m r -> Conduit b m c -> ConduitT a c m r
fuseUpstream ConduitT a b m r
up Conduit b m c
down = ((r, ()) -> r) -> ConduitT a c m (r, ()) -> ConduitT a c m r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (r, ()) -> r
forall a b. (a, b) -> a
fst (ConduitT a b m r -> Conduit b m c -> ConduitT a c m (r, ())
forall (m :: * -> *) a b r1 c r2.
Monad m =>
ConduitT a b m r1 -> ConduitT b c m r2 -> ConduitT a c m (r1, r2)
fuseBoth ConduitT a b m r
up Conduit b m c
down)
{-# INLINE fuseUpstream #-}

-- Rewrite rules

{- FIXME
{-# RULES "conduit: ConduitT: lift x >>= f" forall m f. lift m >>= f = ConduitT (PipeM (liftM (unConduitT . f) m)) #-}
{-# RULES "conduit: ConduitT: lift x >> f" forall m f. lift m >> f = ConduitT (PipeM (liftM (\_ -> unConduitT f) m)) #-}

{-# RULES "conduit: ConduitT: liftIO x >>= f" forall m (f :: MonadIO m => a -> ConduitT i o m r). liftIO m >>= f = ConduitT (PipeM (liftM (unConduitT . f) (liftIO m))) #-}
{-# RULES "conduit: ConduitT: liftIO x >> f" forall m (f :: MonadIO m => ConduitT i o m r). liftIO m >> f = ConduitT (PipeM (liftM (\_ -> unConduitT f) (liftIO m))) #-}

{-# RULES "conduit: ConduitT: liftBase x >>= f" forall m (f :: MonadBase b m => a -> ConduitT i o m r). liftBase m >>= f = ConduitT (PipeM (liftM (unConduitT . f) (liftBase m))) #-}
{-# RULES "conduit: ConduitT: liftBase x >> f" forall m (f :: MonadBase b m => ConduitT i o m r). liftBase m >> f = ConduitT (PipeM (liftM (\_ -> unConduitT f) (liftBase m))) #-}

{-# RULES
    "yield o >> p" forall o (p :: ConduitT i o m r). yield o >> p = ConduitT (HaveOutput (unConduitT p) o)
  ; "when yield next" forall b o p. when b (yield o) >> p =
        if b then ConduitT (HaveOutput (unConduitT p) o) else p
  ; "unless yield next" forall b o p. unless b (yield o) >> p =
        if b then p else ConduitT (HaveOutput (unConduitT p) o)
  ; "lift m >>= yield" forall m. lift m >>= yield = yieldM m
   #-}
{-# RULES "conduit: leftover l >> p" forall l (p :: ConduitT i o m r). leftover l >> p =
    ConduitT (Leftover (unConduitT p) l) #-}
    -}

-- | Run a pure pipeline until processing completes, i.e. a pipeline
-- with @Identity@ as the base monad. This is equivalient to
-- @runIdentity . runConduit@.
--
-- @since 1.2.8
runConduitPure :: ConduitT () Void Identity r -> r
runConduitPure :: ConduitT () Void Identity r -> r
runConduitPure = Identity r -> r
forall a. Identity a -> a
runIdentity (Identity r -> r)
-> (ConduitT () Void Identity r -> Identity r)
-> ConduitT () Void Identity r
-> r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConduitT () Void Identity r -> Identity r
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
runConduit
{-# INLINE runConduitPure #-}

-- | Run a pipeline which acquires resources with @ResourceT@, and
-- then run the @ResourceT@ transformer. This is equivalent to
-- @runResourceT . runConduit@.
--
-- @since 1.2.8
runConduitRes :: MonadUnliftIO m
              => ConduitT () Void (ResourceT m) r
              -> m r
runConduitRes :: ConduitT () Void (ResourceT m) r -> m r
runConduitRes = ResourceT m r -> m r
forall (m :: * -> *) a. MonadUnliftIO m => ResourceT m a -> m a
runResourceT (ResourceT m r -> m r)
-> (ConduitT () Void (ResourceT m) r -> ResourceT m r)
-> ConduitT () Void (ResourceT m) r
-> m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConduitT () Void (ResourceT m) r -> ResourceT m r
forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
runConduit
{-# INLINE runConduitRes #-}