{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE BangPatterns #-}
module Data.Conduit.Combinators
(
yieldMany
, unfold
, enumFromTo
, iterate
, repeat
, replicate
, sourceLazy
, repeatM
, repeatWhileM
, replicateM
, sourceFile
, sourceFileBS
, sourceHandle
, sourceHandleUnsafe
, sourceIOHandle
, stdin
, withSourceFile
, sourceDirectory
, sourceDirectoryDeep
, drop
, dropE
, dropWhile
, dropWhileE
, fold
, foldE
, foldl
, foldl1
, foldlE
, foldMap
, foldMapE
, foldWhile
, all
, allE
, any
, anyE
, and
, andE
, or
, orE
, asum
, elem
, elemE
, notElem
, notElemE
, sinkLazy
, sinkList
, sinkVector
, sinkVectorN
, sinkLazyBuilder
, sinkNull
, awaitNonNull
, head
, headDef
, headE
, peek
, peekE
, last
, lastDef
, lastE
, length
, lengthE
, lengthIf
, lengthIfE
, maximum
, maximumE
, minimum
, minimumE
, null
, nullE
, sum
, sumE
, product
, productE
, find
, mapM_
, mapM_E
, foldM
, foldME
, foldMapM
, foldMapME
, sinkFile
, sinkFileCautious
, sinkTempFile
, sinkSystemTempFile
, sinkFileBS
, sinkHandle
, sinkIOHandle
, print
, stdout
, stderr
, withSinkFile
, withSinkFileBuilder
, withSinkFileCautious
, sinkHandleBuilder
, sinkHandleFlush
, map
, mapE
, omapE
, concatMap
, concatMapE
, take
, takeE
, takeWhile
, takeWhileE
, takeExactly
, takeExactlyE
, concat
, filter
, filterE
, mapWhile
, conduitVector
, scanl
, mapAccumWhile
, concatMapAccum
, intersperse
, slidingWindow
, chunksOfE
, chunksOfExactlyE
, mapM
, mapME
, omapME
, concatMapM
, filterM
, filterME
, iterM
, scanlM
, mapAccumWhileM
, concatMapAccumM
, encodeUtf8
, decodeUtf8
, decodeUtf8Lenient
, line
, lineAscii
, unlines
, unlinesAscii
, takeExactlyUntilE
, linesUnbounded
, linesUnboundedAscii
, splitOnUnboundedE
, builderToByteString
, unsafeBuilderToByteString
, builderToByteStringWith
, builderToByteStringFlush
, builderToByteStringWithFlush
, BufferAllocStrategy
, allNewBuffersStrategy
, reuseBufferStrategy
, vectorBuilder
, mapAccumS
, peekForever
, peekForeverE
) where
import Data.ByteString.Builder (Builder, toLazyByteString, hPutBuilder)
import qualified Data.ByteString.Builder.Internal as BB (flush)
import qualified Data.ByteString.Builder.Extra as BB (runBuilder, Next(Done, More, Chunk))
import qualified Data.NonNull as NonNull
import qualified Data.Traversable
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as BL
import Data.ByteString.Lazy.Internal (defaultChunkSize)
import Control.Applicative (Alternative(..), (<$>))
import Control.Exception (catch, throwIO, finally, bracket, try, evaluate)
import Control.Category (Category (..))
import Control.Monad (unless, when, (>=>), liftM, forever)
import Control.Monad.IO.Unlift (MonadIO (..), MonadUnliftIO, withRunInIO)
import Control.Monad.Primitive (PrimMonad, PrimState, unsafePrimToPrim)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Resource (MonadResource, MonadThrow, allocate, throwM)
import Data.Conduit
import Data.Conduit.Internal (ConduitT (..), Pipe (..))
import qualified Data.Conduit.List as CL
import Data.IORef
import Data.Maybe (fromMaybe, isNothing, isJust)
import Data.Monoid (Monoid (..))
import Data.MonoTraversable
import qualified Data.Sequences as Seq
import qualified Data.Vector.Generic as V
import qualified Data.Vector.Generic.Mutable as VM
import Data.Void (absurd)
import Prelude (Bool (..), Eq (..), Int,
Maybe (..), Either (..), Monad (..), Num (..),
Ord (..), fromIntegral, maybe, either,
($), Functor (..), Enum, seq, Show, Char,
otherwise, Either (..), not,
($!), succ, FilePath, IO, String)
import Data.Word (Word8)
import qualified Prelude
import qualified System.IO as IO
import System.IO.Error (isDoesNotExistError)
import System.IO.Unsafe (unsafePerformIO)
import Data.ByteString (ByteString)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.Encoding.Error as TEE
import Data.Conduit.Combinators.Stream
import Data.Conduit.Internal.Fusion
import Data.Primitive.MutVar (MutVar, newMutVar, readMutVar,
writeMutVar)
import qualified Data.Streaming.FileRead as FR
import qualified Data.Streaming.Filesystem as F
import GHC.ForeignPtr (mallocPlainForeignPtrBytes, unsafeForeignPtrToPtr)
import Foreign.ForeignPtr (touchForeignPtr, ForeignPtr)
import Foreign.Ptr (Ptr, plusPtr, minusPtr)
import Data.ByteString.Internal (ByteString (PS), mallocByteString)
import System.FilePath ((</>), (<.>), takeDirectory, takeFileName)
import System.Directory (renameFile, getTemporaryDirectory, removeFile)
import qualified Data.Sequences as DTE
import Data.Sequences (LazySequence (..))
#include "fusion-macros.h"
yieldMany, yieldManyC :: (Monad m, MonoFoldable mono)
=> mono
-> ConduitT i (Element mono) m ()
yieldManyC :: forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldManyC = (Element mono -> ConduitT i (Element mono) m ())
-> mono -> ConduitT i (Element mono) m ()
forall m. Monoid m => (Element mono -> m) -> mono -> m
forall mono m.
(MonoFoldable mono, Monoid m) =>
(Element mono -> m) -> mono -> m
ofoldMap Element mono -> ConduitT i (Element mono) m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE yieldManyC #-}
STREAMING(yieldMany, yieldManyC, yieldManyS, x)
unfold :: Monad m
=> (b -> Maybe (a, b))
-> b
-> ConduitT i a m ()
INLINE_RULE(unfold, f x, CL.unfold f x)
enumFromTo :: (Monad m, Enum a, Ord a) => a -> a -> ConduitT i a m ()
INLINE_RULE(enumFromTo, f t, CL.enumFromTo f t)
iterate :: Monad m => (a -> a) -> a -> ConduitT i a m ()
INLINE_RULE(iterate, f t, CL.iterate f t)
repeat :: Monad m => a -> ConduitT i a m ()
INLINE_RULE(repeat, x, iterate id x)
replicate :: Monad m
=> Int
-> a
-> ConduitT i a m ()
INLINE_RULE(replicate, n x, CL.replicate n x)
sourceLazy :: (Monad m, LazySequence lazy strict)
=> lazy
-> ConduitT i strict m ()
INLINE_RULE(sourceLazy, x, yieldMany (toChunks x))
repeatM, repeatMC :: Monad m
=> m a
-> ConduitT i a m ()
repeatMC :: forall (m :: * -> *) a i. Monad m => m a -> ConduitT i a m ()
repeatMC m a
m = ConduitT i a m () -> ConduitT i a m ()
forall (f :: * -> *) a b. Applicative f => f a -> f b
forever (ConduitT i a m () -> ConduitT i a m ())
-> ConduitT i a m () -> ConduitT i a m ()
forall a b. (a -> b) -> a -> b
$ m a -> ConduitT i a m a
forall (m :: * -> *) a. Monad m => m a -> ConduitT i a m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m a
m ConduitT i a m a -> (a -> ConduitT i a m ()) -> ConduitT i a m ()
forall a b.
ConduitT i a m a -> (a -> ConduitT i a m b) -> ConduitT i a m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> ConduitT i a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE repeatMC #-}
STREAMING(repeatM, repeatMC, repeatMS, m)
repeatWhileM, repeatWhileMC :: Monad m
=> m a
-> (a -> Bool)
-> ConduitT i a m ()
repeatWhileMC :: forall (m :: * -> *) a i.
Monad m =>
m a -> (a -> Bool) -> ConduitT i a m ()
repeatWhileMC m a
m a -> Bool
f =
ConduitT i a m ()
loop
where
loop :: ConduitT i a m ()
loop = do
a
x <- m a -> ConduitT i a m a
forall (m :: * -> *) a. Monad m => m a -> ConduitT i a m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m a
m
Bool -> ConduitT i a m () -> ConduitT i a m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (a -> Bool
f a
x) (ConduitT i a m () -> ConduitT i a m ())
-> ConduitT i a m () -> ConduitT i a m ()
forall a b. (a -> b) -> a -> b
$ a -> ConduitT i a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
x ConduitT i a m () -> ConduitT i a m () -> ConduitT i a m ()
forall a b.
ConduitT i a m a -> ConduitT i a m b -> ConduitT i a m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT i a m ()
loop
STREAMING(repeatWhileM, repeatWhileMC, repeatWhileMS, m f)
replicateM :: Monad m
=> Int
-> m a
-> ConduitT i a m ()
INLINE_RULE(replicateM, n m, CL.replicateM n m)
sourceFile :: MonadResource m
=> FilePath
-> ConduitT i S.ByteString m ()
sourceFile :: forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i ByteString m ()
sourceFile FilePath
fp =
IO ReadHandle
-> (ReadHandle -> IO ())
-> (ReadHandle -> ConduitT i ByteString m ())
-> ConduitT i ByteString m ()
forall (m :: * -> *) a i o r.
MonadResource m =>
IO a -> (a -> IO ()) -> (a -> ConduitT i o m r) -> ConduitT i o m r
bracketP
(FilePath -> IO ReadHandle
FR.openFile FilePath
fp)
ReadHandle -> IO ()
FR.closeFile
ReadHandle -> ConduitT i ByteString m ()
forall {m :: * -> *} {i}.
MonadIO m =>
ReadHandle -> ConduitT i ByteString m ()
loop
where
loop :: ReadHandle -> ConduitT i ByteString m ()
loop ReadHandle
h = do
ByteString
bs <- IO ByteString -> ConduitT i ByteString m ByteString
forall a. IO a -> ConduitT i ByteString m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO ByteString -> ConduitT i ByteString m ByteString)
-> IO ByteString -> ConduitT i ByteString m ByteString
forall a b. (a -> b) -> a -> b
$ ReadHandle -> IO ByteString
FR.readChunk ReadHandle
h
Bool -> ConduitT i ByteString m () -> ConduitT i ByteString m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) (ConduitT i ByteString m () -> ConduitT i ByteString m ())
-> ConduitT i ByteString m () -> ConduitT i ByteString m ()
forall a b. (a -> b) -> a -> b
$ do
ByteString -> ConduitT i ByteString m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield ByteString
bs
ReadHandle -> ConduitT i ByteString m ()
loop ReadHandle
h
sourceHandle :: MonadIO m
=> IO.Handle
-> ConduitT i S.ByteString m ()
sourceHandle :: forall (m :: * -> *) i.
MonadIO m =>
Handle -> ConduitT i ByteString m ()
sourceHandle Handle
h =
ConduitT i ByteString m ()
loop
where
loop :: ConduitT i ByteString m ()
loop = do
ByteString
bs <- IO ByteString -> ConduitT i ByteString m ByteString
forall a. IO a -> ConduitT i ByteString m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Handle -> Int -> IO ByteString
S.hGetSome Handle
h Int
defaultChunkSize)
if ByteString -> Bool
S.null ByteString
bs
then () -> ConduitT i ByteString m ()
forall a. a -> ConduitT i ByteString m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else ByteString -> ConduitT i ByteString m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield ByteString
bs ConduitT i ByteString m ()
-> ConduitT i ByteString m () -> ConduitT i ByteString m ()
forall a b.
ConduitT i ByteString m a
-> ConduitT i ByteString m b -> ConduitT i ByteString m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT i ByteString m ()
loop
sourceHandleUnsafe :: MonadIO m => IO.Handle -> ConduitT i ByteString m ()
sourceHandleUnsafe :: forall (m :: * -> *) i.
MonadIO m =>
Handle -> ConduitT i ByteString m ()
sourceHandleUnsafe Handle
handle = do
ForeignPtr Word8
fptr <- IO (ForeignPtr Word8) -> ConduitT i ByteString m (ForeignPtr Word8)
forall a. IO a -> ConduitT i ByteString m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (ForeignPtr Word8)
-> ConduitT i ByteString m (ForeignPtr Word8))
-> IO (ForeignPtr Word8)
-> ConduitT i ByteString m (ForeignPtr Word8)
forall a b. (a -> b) -> a -> b
$ Int -> IO (ForeignPtr Word8)
forall a. Int -> IO (ForeignPtr a)
mallocPlainForeignPtrBytes Int
defaultChunkSize
let ptr :: Ptr Word8
ptr = ForeignPtr Word8 -> Ptr Word8
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fptr
loop :: ConduitT i ByteString m ()
loop = do
Int
count <- IO Int -> ConduitT i ByteString m Int
forall a. IO a -> ConduitT i ByteString m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int -> ConduitT i ByteString m Int)
-> IO Int -> ConduitT i ByteString m Int
forall a b. (a -> b) -> a -> b
$ Handle -> Ptr Word8 -> Int -> IO Int
forall a. Handle -> Ptr a -> Int -> IO Int
IO.hGetBuf Handle
handle Ptr Word8
ptr Int
defaultChunkSize
Bool -> ConduitT i ByteString m () -> ConduitT i ByteString m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
count Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0) (ConduitT i ByteString m () -> ConduitT i ByteString m ())
-> ConduitT i ByteString m () -> ConduitT i ByteString m ()
forall a b. (a -> b) -> a -> b
$ do
ByteString -> ConduitT i ByteString m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fptr Int
0 Int
count)
ConduitT i ByteString m ()
loop
ConduitT i ByteString m ()
loop
IO () -> ConduitT i ByteString m ()
forall a. IO a -> ConduitT i ByteString m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitT i ByteString m ())
-> IO () -> ConduitT i ByteString m ()
forall a b. (a -> b) -> a -> b
$ ForeignPtr Word8 -> IO ()
forall a. ForeignPtr a -> IO ()
touchForeignPtr ForeignPtr Word8
fptr
sourceIOHandle :: MonadResource m
=> IO IO.Handle
-> ConduitT i S.ByteString m ()
sourceIOHandle :: forall (m :: * -> *) i.
MonadResource m =>
IO Handle -> ConduitT i ByteString m ()
sourceIOHandle IO Handle
alloc = IO Handle
-> (Handle -> IO ())
-> (Handle -> ConduitT i ByteString m ())
-> ConduitT i ByteString m ()
forall (m :: * -> *) a i o r.
MonadResource m =>
IO a -> (a -> IO ()) -> (a -> ConduitT i o m r) -> ConduitT i o m r
bracketP IO Handle
alloc Handle -> IO ()
IO.hClose Handle -> ConduitT i ByteString m ()
forall (m :: * -> *) i.
MonadIO m =>
Handle -> ConduitT i ByteString m ()
sourceHandle
sourceFileBS :: MonadResource m => FilePath -> ConduitT i ByteString m ()
sourceFileBS :: forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i ByteString m ()
sourceFileBS = FilePath -> ConduitT i ByteString m ()
forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i ByteString m ()
sourceFile
{-# INLINE sourceFileBS #-}
stdin :: MonadIO m => ConduitT i ByteString m ()
INLINE_RULE0(stdin, sourceHandle IO.stdin)
sinkFile :: MonadResource m
=> FilePath
-> ConduitT S.ByteString o m ()
sinkFile :: forall (m :: * -> *) o.
MonadResource m =>
FilePath -> ConduitT ByteString o m ()
sinkFile FilePath
fp = IO Handle -> ConduitT ByteString o m ()
forall (m :: * -> *) o.
MonadResource m =>
IO Handle -> ConduitT ByteString o m ()
sinkIOHandle (FilePath -> IOMode -> IO Handle
IO.openBinaryFile FilePath
fp IOMode
IO.WriteMode)
sinkFileCautious
:: MonadResource m
=> FilePath
-> ConduitM S.ByteString o m ()
sinkFileCautious :: forall (m :: * -> *) o.
MonadResource m =>
FilePath -> ConduitT ByteString o m ()
sinkFileCautious FilePath
fp =
IO (FilePath, Handle)
-> ((FilePath, Handle) -> IO ())
-> ((FilePath, Handle) -> ConduitT ByteString o m ())
-> ConduitT ByteString o m ()
forall (m :: * -> *) a i o r.
MonadResource m =>
IO a -> (a -> IO ()) -> (a -> ConduitT i o m r) -> ConduitT i o m r
bracketP (FilePath -> IO (FilePath, Handle)
cautiousAcquire FilePath
fp) (FilePath, Handle) -> IO ()
cautiousCleanup (FilePath, Handle) -> ConduitT ByteString o m ()
inner
where
inner :: (FilePath, Handle) -> ConduitT ByteString o m ()
inner (FilePath
tmpFP, Handle
h) = do
Handle -> ConduitT ByteString o m ()
forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle Handle
h
IO () -> ConduitT ByteString o m ()
forall a. IO a -> ConduitT ByteString o m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitT ByteString o m ())
-> IO () -> ConduitT ByteString o m ()
forall a b. (a -> b) -> a -> b
$ do
Handle -> IO ()
IO.hClose Handle
h
FilePath -> FilePath -> IO ()
renameFile FilePath
tmpFP FilePath
fp
withSinkFileCautious
:: (MonadUnliftIO m, MonadIO n)
=> FilePath
-> (ConduitM S.ByteString o n () -> m a)
-> m a
withSinkFileCautious :: forall (m :: * -> *) (n :: * -> *) o a.
(MonadUnliftIO m, MonadIO n) =>
FilePath -> (ConduitM ByteString o n () -> m a) -> m a
withSinkFileCautious FilePath
fp ConduitM ByteString o n () -> m a
inner =
((forall a. m a -> IO a) -> IO a) -> m a
forall b. ((forall a. m a -> IO a) -> IO b) -> 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 a) -> m a)
-> ((forall a. m a -> IO a) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> IO (FilePath, Handle)
-> ((FilePath, Handle) -> IO ())
-> ((FilePath, Handle) -> IO a)
-> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket
(FilePath -> IO (FilePath, Handle)
cautiousAcquire FilePath
fp)
(FilePath, Handle) -> IO ()
cautiousCleanup
(\(FilePath
tmpFP, Handle
h) -> do
a
a <- m a -> IO a
forall a. m a -> IO a
run (m a -> IO a) -> m a -> IO a
forall a b. (a -> b) -> a -> b
$ ConduitM ByteString o n () -> m a
inner (ConduitM ByteString o n () -> m a)
-> ConduitM ByteString o n () -> m a
forall a b. (a -> b) -> a -> b
$ Handle -> ConduitM ByteString o n ()
forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle Handle
h
Handle -> IO ()
IO.hClose Handle
h
FilePath -> FilePath -> IO ()
renameFile FilePath
tmpFP FilePath
fp
a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a)
cautiousAcquire :: FilePath -> IO (FilePath, IO.Handle)
cautiousAcquire :: FilePath -> IO (FilePath, Handle)
cautiousAcquire FilePath
fp = FilePath -> FilePath -> IO (FilePath, Handle)
IO.openBinaryTempFile (FilePath -> FilePath
takeDirectory FilePath
fp) (FilePath -> FilePath
takeFileName FilePath
fp FilePath -> FilePath -> FilePath
<.> FilePath
"tmp")
cautiousCleanup :: (FilePath, IO.Handle) -> IO ()
cautiousCleanup :: (FilePath, Handle) -> IO ()
cautiousCleanup (FilePath
tmpFP, Handle
h) = do
Handle -> IO ()
IO.hClose Handle
h
FilePath -> IO ()
removeFile FilePath
tmpFP IO () -> (IOError -> IO ()) -> IO ()
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`Control.Exception.catch` \IOError
e ->
if IOError -> Bool
isDoesNotExistError IOError
e
then () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else IOError -> IO ()
forall e a. Exception e => e -> IO a
throwIO IOError
e
sinkTempFile :: MonadResource m
=> FilePath
-> String
-> ConduitM ByteString o m FilePath
sinkTempFile :: forall (m :: * -> *) o.
MonadResource m =>
FilePath -> FilePath -> ConduitM ByteString o m FilePath
sinkTempFile FilePath
tmpdir FilePath
pattern = do
(ReleaseKey
_releaseKey, (FilePath
fp, Handle
h)) <- IO (FilePath, Handle)
-> ((FilePath, Handle) -> IO ())
-> ConduitT ByteString o m (ReleaseKey, (FilePath, Handle))
forall (m :: * -> *) a.
MonadResource m =>
IO a -> (a -> IO ()) -> m (ReleaseKey, a)
allocate
(FilePath -> FilePath -> IO (FilePath, Handle)
IO.openBinaryTempFile FilePath
tmpdir FilePath
pattern)
(\(FilePath
fp, Handle
h) -> Handle -> IO ()
IO.hClose Handle
h IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO a
`finally` (FilePath -> IO ()
removeFile FilePath
fp IO () -> (IOError -> IO ()) -> IO ()
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`Control.Exception.catch` \IOError
e ->
if IOError -> Bool
isDoesNotExistError IOError
e
then () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else IOError -> IO ()
forall e a. Exception e => e -> IO a
throwIO IOError
e))
Handle -> ConduitT ByteString o m ()
forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle Handle
h
IO () -> ConduitT ByteString o m ()
forall a. IO a -> ConduitT ByteString o m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitT ByteString o m ())
-> IO () -> ConduitT ByteString o m ()
forall a b. (a -> b) -> a -> b
$ Handle -> IO ()
IO.hClose Handle
h
FilePath -> ConduitM ByteString o m FilePath
forall a. a -> ConduitT ByteString o m a
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
fp
sinkSystemTempFile
:: MonadResource m
=> String
-> ConduitM ByteString o m FilePath
sinkSystemTempFile :: forall (m :: * -> *) o.
MonadResource m =>
FilePath -> ConduitM ByteString o m FilePath
sinkSystemTempFile FilePath
pattern = do
FilePath
dir <- IO FilePath -> ConduitM ByteString o m FilePath
forall a. IO a -> ConduitT ByteString o m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO FilePath
getTemporaryDirectory
FilePath -> FilePath -> ConduitM ByteString o m FilePath
forall (m :: * -> *) o.
MonadResource m =>
FilePath -> FilePath -> ConduitM ByteString o m FilePath
sinkTempFile FilePath
dir FilePath
pattern
sinkHandle :: MonadIO m
=> IO.Handle
-> ConduitT S.ByteString o m ()
sinkHandle :: forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle Handle
h = (ByteString -> ConduitT ByteString o m ())
-> ConduitT ByteString o m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (IO () -> ConduitT ByteString o m ()
forall a. IO a -> ConduitT ByteString o m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitT ByteString o m ())
-> (ByteString -> IO ())
-> ByteString
-> ConduitT ByteString o m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> ByteString -> IO ()
S.hPut Handle
h)
sinkHandleBuilder :: MonadIO m => IO.Handle -> ConduitM Builder o m ()
sinkHandleBuilder :: forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitM Builder o m ()
sinkHandleBuilder Handle
h = (Builder -> ConduitT Builder o m ()) -> ConduitT Builder o m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (IO () -> ConduitT Builder o m ()
forall a. IO a -> ConduitT Builder o m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitT Builder o m ())
-> (Builder -> IO ()) -> Builder -> ConduitT Builder o m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> Builder -> IO ()
hPutBuilder Handle
h)
sinkHandleFlush :: MonadIO m
=> IO.Handle
-> ConduitM (Flush S.ByteString) o m ()
sinkHandleFlush :: forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitM (Flush ByteString) o m ()
sinkHandleFlush Handle
h =
(Flush ByteString -> ConduitT (Flush ByteString) o m ())
-> ConduitT (Flush ByteString) o m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever ((Flush ByteString -> ConduitT (Flush ByteString) o m ())
-> ConduitT (Flush ByteString) o m ())
-> (Flush ByteString -> ConduitT (Flush ByteString) o m ())
-> ConduitT (Flush ByteString) o m ()
forall a b. (a -> b) -> a -> b
$ \Flush ByteString
mbs -> IO () -> ConduitT (Flush ByteString) o m ()
forall a. IO a -> ConduitT (Flush ByteString) o m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ConduitT (Flush ByteString) o m ())
-> IO () -> ConduitT (Flush ByteString) o m ()
forall a b. (a -> b) -> a -> b
$
case Flush ByteString
mbs of
Chunk ByteString
bs -> Handle -> ByteString -> IO ()
S.hPut Handle
h ByteString
bs
Flush ByteString
Flush -> Handle -> IO ()
IO.hFlush Handle
h
sinkIOHandle :: MonadResource m
=> IO IO.Handle
-> ConduitT S.ByteString o m ()
sinkIOHandle :: forall (m :: * -> *) o.
MonadResource m =>
IO Handle -> ConduitT ByteString o m ()
sinkIOHandle IO Handle
alloc = IO Handle
-> (Handle -> IO ())
-> (Handle -> ConduitT ByteString o m ())
-> ConduitT ByteString o m ()
forall (m :: * -> *) a i o r.
MonadResource m =>
IO a -> (a -> IO ()) -> (a -> ConduitT i o m r) -> ConduitT i o m r
bracketP IO Handle
alloc Handle -> IO ()
IO.hClose Handle -> ConduitT ByteString o m ()
forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle
withSourceFile
:: (MonadUnliftIO m, MonadIO n)
=> FilePath
-> (ConduitM i ByteString n () -> m a)
-> m a
withSourceFile :: forall (m :: * -> *) (n :: * -> *) i a.
(MonadUnliftIO m, MonadIO n) =>
FilePath -> (ConduitM i ByteString n () -> m a) -> m a
withSourceFile FilePath
fp ConduitM i ByteString n () -> m a
inner =
((forall a. m a -> IO a) -> IO a) -> m a
forall b. ((forall a. m a -> IO a) -> IO b) -> 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 a) -> m a)
-> ((forall a. m a -> IO a) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
FilePath -> IOMode -> (Handle -> IO a) -> IO a
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
IO.withBinaryFile FilePath
fp IOMode
IO.ReadMode ((Handle -> IO a) -> IO a) -> (Handle -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$
m a -> IO a
forall a. m a -> IO a
run (m a -> IO a) -> (Handle -> m a) -> Handle -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ConduitM i ByteString n () -> m a
inner (ConduitM i ByteString n () -> m a)
-> (Handle -> ConduitM i ByteString n ()) -> Handle -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> ConduitM i ByteString n ()
forall (m :: * -> *) i.
MonadIO m =>
Handle -> ConduitT i ByteString m ()
sourceHandle
withSinkFile
:: (MonadUnliftIO m, MonadIO n)
=> FilePath
-> (ConduitM ByteString o n () -> m a)
-> m a
withSinkFile :: forall (m :: * -> *) (n :: * -> *) o a.
(MonadUnliftIO m, MonadIO n) =>
FilePath -> (ConduitM ByteString o n () -> m a) -> m a
withSinkFile FilePath
fp ConduitM ByteString o n () -> m a
inner =
((forall a. m a -> IO a) -> IO a) -> m a
forall b. ((forall a. m a -> IO a) -> IO b) -> 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 a) -> m a)
-> ((forall a. m a -> IO a) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
FilePath -> IOMode -> (Handle -> IO a) -> IO a
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
IO.withBinaryFile FilePath
fp IOMode
IO.WriteMode ((Handle -> IO a) -> IO a) -> (Handle -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$
m a -> IO a
forall a. m a -> IO a
run (m a -> IO a) -> (Handle -> m a) -> Handle -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ConduitM ByteString o n () -> m a
inner (ConduitM ByteString o n () -> m a)
-> (Handle -> ConduitM ByteString o n ()) -> Handle -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> ConduitM ByteString o n ()
forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle
withSinkFileBuilder
:: (MonadUnliftIO m, MonadIO n)
=> FilePath
-> (ConduitM Builder o n () -> m a)
-> m a
withSinkFileBuilder :: forall (m :: * -> *) (n :: * -> *) o a.
(MonadUnliftIO m, MonadIO n) =>
FilePath -> (ConduitM Builder o n () -> m a) -> m a
withSinkFileBuilder FilePath
fp ConduitM Builder o n () -> m a
inner =
((forall a. m a -> IO a) -> IO a) -> m a
forall b. ((forall a. m a -> IO a) -> IO b) -> 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 a) -> m a)
-> ((forall a. m a -> IO a) -> IO a) -> m a
forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
FilePath -> IOMode -> (Handle -> IO a) -> IO a
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
IO.withBinaryFile FilePath
fp IOMode
IO.WriteMode ((Handle -> IO a) -> IO a) -> (Handle -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \Handle
h ->
m a -> IO a
forall a. m a -> IO a
run (m a -> IO a) -> m a -> IO a
forall a b. (a -> b) -> a -> b
$ ConduitM Builder o n () -> m a
inner (ConduitM Builder o n () -> m a) -> ConduitM Builder o n () -> m a
forall a b. (a -> b) -> a -> b
$ (Builder -> n ()) -> ConduitM Builder o n ()
forall (m :: * -> *) a o.
Monad m =>
(a -> m ()) -> ConduitT a o m ()
CL.mapM_ (IO () -> n ()
forall a. IO a -> n a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> n ()) -> (Builder -> IO ()) -> Builder -> n ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Handle -> Builder -> IO ()
hPutBuilder Handle
h)
sourceDirectory :: MonadResource m => FilePath -> ConduitT i FilePath m ()
sourceDirectory :: forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
sourceDirectory FilePath
dir =
IO DirStream
-> (DirStream -> IO ())
-> (DirStream -> ConduitT i FilePath m ())
-> ConduitT i FilePath m ()
forall (m :: * -> *) a i o r.
MonadResource m =>
IO a -> (a -> IO ()) -> (a -> ConduitT i o m r) -> ConduitT i o m r
bracketP (FilePath -> IO DirStream
F.openDirStream FilePath
dir) DirStream -> IO ()
F.closeDirStream DirStream -> ConduitT i FilePath m ()
go
where
go :: DirStream -> ConduitT i FilePath m ()
go DirStream
ds =
ConduitT i FilePath m ()
loop
where
loop :: ConduitT i FilePath m ()
loop = do
Maybe FilePath
mfp <- IO (Maybe FilePath) -> ConduitT i FilePath m (Maybe FilePath)
forall a. IO a -> ConduitT i FilePath m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe FilePath) -> ConduitT i FilePath m (Maybe FilePath))
-> IO (Maybe FilePath) -> ConduitT i FilePath m (Maybe FilePath)
forall a b. (a -> b) -> a -> b
$ DirStream -> IO (Maybe FilePath)
F.readDirStream DirStream
ds
case Maybe FilePath
mfp of
Maybe FilePath
Nothing -> () -> ConduitT i FilePath m ()
forall a. a -> ConduitT i FilePath m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just FilePath
fp -> do
FilePath -> ConduitT i FilePath m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (FilePath -> ConduitT i FilePath m ())
-> FilePath -> ConduitT i FilePath m ()
forall a b. (a -> b) -> a -> b
$ FilePath
dir FilePath -> FilePath -> FilePath
</> FilePath
fp
ConduitT i FilePath m ()
loop
sourceDirectoryDeep :: MonadResource m
=> Bool
-> FilePath
-> ConduitT i FilePath m ()
sourceDirectoryDeep :: forall (m :: * -> *) i.
MonadResource m =>
Bool -> FilePath -> ConduitT i FilePath m ()
sourceDirectoryDeep Bool
followSymlinks =
FilePath -> ConduitT i FilePath m ()
forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
start
where
start :: MonadResource m => FilePath -> ConduitT i FilePath m ()
start :: forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
start FilePath
dir = FilePath -> ConduitT i FilePath m ()
forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
sourceDirectory FilePath
dir ConduitT i FilePath m ()
-> ConduitT FilePath FilePath m () -> ConduitT i FilePath m ()
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| (FilePath -> ConduitT FilePath FilePath m ())
-> ConduitT FilePath FilePath m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever FilePath -> ConduitT FilePath FilePath m ()
forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
go
go :: MonadResource m => FilePath -> ConduitT i FilePath m ()
go :: forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
go FilePath
fp = do
FileType
ft <- IO FileType -> ConduitT i FilePath m FileType
forall a. IO a -> ConduitT i FilePath m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FileType -> ConduitT i FilePath m FileType)
-> IO FileType -> ConduitT i FilePath m FileType
forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileType
F.getFileType FilePath
fp
case FileType
ft of
FileType
F.FTFile -> FilePath -> ConduitT i FilePath m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield FilePath
fp
FileType
F.FTFileSym -> FilePath -> ConduitT i FilePath m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield FilePath
fp
FileType
F.FTDirectory -> FilePath -> ConduitT i FilePath m ()
forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
start FilePath
fp
FileType
F.FTDirectorySym
| Bool
followSymlinks -> FilePath -> ConduitT i FilePath m ()
forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
start FilePath
fp
| Bool
otherwise -> () -> ConduitT i FilePath m ()
forall a. a -> ConduitT i FilePath m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
FileType
F.FTOther -> () -> ConduitT i FilePath m ()
forall a. a -> ConduitT i FilePath m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
drop :: Monad m
=> Int
-> ConduitT a o m ()
INLINE_RULE(drop, n, CL.drop n)
dropE :: (Monad m, Seq.IsSequence seq)
=> Seq.Index seq
-> ConduitT seq o m ()
dropE :: forall (m :: * -> *) seq o.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq o m ()
dropE =
Index seq -> ConduitT seq o m ()
forall {mono} {m :: * -> *} {o}.
(Monad m, IsSequence mono) =>
Index mono -> ConduitT mono o m ()
loop
where
loop :: Index mono -> ConduitT mono o m ()
loop Index mono
i = if Index mono
i Index mono -> Index mono -> Bool
forall a. Ord a => a -> a -> Bool
<= Index mono
0
then () -> ConduitT mono o m ()
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else ConduitT mono o m (Maybe mono)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT mono o m (Maybe mono)
-> (Maybe mono -> ConduitT mono o m ()) -> ConduitT mono o m ()
forall a b.
ConduitT mono o m a
-> (a -> ConduitT mono o m b) -> ConduitT mono o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT mono o m ()
-> (mono -> ConduitT mono o m ())
-> Maybe mono
-> ConduitT mono o m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT mono o m ()
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Index mono -> mono -> ConduitT mono o m ()
go Index mono
i)
go :: Index mono -> mono -> ConduitT mono o m ()
go Index mono
i mono
sq = do
Bool -> ConduitT mono o m () -> ConduitT mono o m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (mono -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull mono
y) (ConduitT mono o m () -> ConduitT mono o m ())
-> ConduitT mono o m () -> ConduitT mono o m ()
forall a b. (a -> b) -> a -> b
$ mono -> ConduitT mono o m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
y
Index mono -> ConduitT mono o m ()
loop Index mono
i'
where
(mono
x, mono
y) = Index mono -> mono -> (mono, mono)
forall seq. IsSequence seq => Index seq -> seq -> (seq, seq)
Seq.splitAt Index mono
i mono
sq
i' :: Index mono
i' = Index mono
i Index mono -> Index mono -> Index mono
forall a. Num a => a -> a -> a
- Int -> Index mono
forall a b. (Integral a, Num b) => a -> b
fromIntegral (mono -> Int
forall mono. MonoFoldable mono => mono -> Int
olength mono
x)
{-# INLINEABLE dropE #-}
dropWhile :: Monad m
=> (a -> Bool)
-> ConduitT a o m ()
dropWhile :: forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m ()
dropWhile a -> Bool
f =
ConduitT a o m ()
loop
where
loop :: ConduitT a o m ()
loop = ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a o m (Maybe a)
-> (Maybe a -> ConduitT a o m ()) -> ConduitT a o m ()
forall a b.
ConduitT a o m a -> (a -> ConduitT a o m b) -> ConduitT a o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a o m ()
-> (a -> ConduitT a o m ()) -> Maybe a -> ConduitT a o m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT a o m ()
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) a -> ConduitT a o m ()
go
go :: a -> ConduitT a o m ()
go a
x = if a -> Bool
f a
x then ConduitT a o m ()
loop else a -> ConduitT a o m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover a
x
{-# INLINE dropWhile #-}
dropWhileE :: (Monad m, Seq.IsSequence seq)
=> (Element seq -> Bool)
-> ConduitT seq o m ()
dropWhileE :: forall (m :: * -> *) seq o.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq o m ()
dropWhileE Element seq -> Bool
f =
ConduitT seq o m ()
loop
where
loop :: ConduitT seq o m ()
loop = ConduitT seq o m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT seq o m (Maybe seq)
-> (Maybe seq -> ConduitT seq o m ()) -> ConduitT seq o m ()
forall a b.
ConduitT seq o m a
-> (a -> ConduitT seq o m b) -> ConduitT seq o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT seq o m ()
-> (seq -> ConduitT seq o m ()) -> Maybe seq -> ConduitT seq o m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT seq o m ()
forall a. a -> ConduitT seq o m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) seq -> ConduitT seq o m ()
go
go :: seq -> ConduitT seq o m ()
go seq
sq =
if seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
x then ConduitT seq o m ()
loop else seq -> ConduitT seq o m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover seq
x
where
x :: seq
x = (Element seq -> Bool) -> seq -> seq
forall seq. IsSequence seq => (Element seq -> Bool) -> seq -> seq
Seq.dropWhile Element seq -> Bool
f seq
sq
{-# INLINE dropWhileE #-}
fold :: (Monad m, Monoid a)
=> ConduitT a o m a
INLINE_RULE0(fold, CL.foldMap id)
foldE :: (Monad m, MonoFoldable mono, Monoid (Element mono))
=> ConduitT mono o m (Element mono)
INLINE_RULE0(foldE, CL.fold (\accum mono -> accum `mappend` ofoldMap id mono) mempty)
foldl :: Monad m => (a -> b -> a) -> a -> ConduitT b o m a
INLINE_RULE(foldl, f x, CL.fold f x)
foldlE :: (Monad m, MonoFoldable mono)
=> (a -> Element mono -> a)
-> a
-> ConduitT mono o m a
INLINE_RULE(foldlE, f x, CL.fold (ofoldlPrime f) x)
ofoldlPrime :: MonoFoldable mono => (a -> Element mono -> a) -> a -> mono -> a
ofoldlPrime :: forall mono a.
MonoFoldable mono =>
(a -> Element mono -> a) -> a -> mono -> a
ofoldlPrime = (a -> Element mono -> a) -> a -> mono -> a
forall mono a.
MonoFoldable mono =>
(a -> Element mono -> a) -> a -> mono -> a
forall a. (a -> Element mono -> a) -> a -> mono -> a
ofoldl'
foldMap :: (Monad m, Monoid b)
=> (a -> b)
-> ConduitT a o m b
INLINE_RULE(foldMap, f, CL.foldMap f)
foldMapE :: (Monad m, MonoFoldable mono, Monoid w)
=> (Element mono -> w)
-> ConduitT mono o m w
INLINE_RULE(foldMapE, f, CL.foldMap (ofoldMap f))
foldl1, foldl1C :: Monad m => (a -> a -> a) -> ConduitT a o m (Maybe a)
foldl1C :: forall (m :: * -> *) a o.
Monad m =>
(a -> a -> a) -> ConduitT a o m (Maybe a)
foldl1C a -> a -> a
f =
ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a o m (Maybe a)
-> (Maybe a -> ConduitT a o m (Maybe a))
-> ConduitT a o m (Maybe a)
forall a b.
ConduitT a o m a -> (a -> ConduitT a o m b) -> ConduitT a o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a o m (Maybe a)
-> (a -> ConduitT a o m (Maybe a))
-> Maybe a
-> ConduitT a o m (Maybe a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe a -> ConduitT a o m (Maybe a)
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing) a -> ConduitT a o m (Maybe a)
loop
where
loop :: a -> ConduitT a o m (Maybe a)
loop !a
prev = ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a o m (Maybe a)
-> (Maybe a -> ConduitT a o m (Maybe a))
-> ConduitT a o m (Maybe a)
forall a b.
ConduitT a o m a -> (a -> ConduitT a o m b) -> ConduitT a o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a o m (Maybe a)
-> (a -> ConduitT a o m (Maybe a))
-> Maybe a
-> ConduitT a o m (Maybe a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe a -> ConduitT a o m (Maybe a)
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> ConduitT a o m (Maybe a))
-> Maybe a -> ConduitT a o m (Maybe a)
forall a b. (a -> b) -> a -> b
$ a -> Maybe a
forall a. a -> Maybe a
Just a
prev) (a -> ConduitT a o m (Maybe a)
loop (a -> ConduitT a o m (Maybe a))
-> (a -> a) -> a -> ConduitT a o m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> a -> a
f a
prev)
STREAMING(foldl1, foldl1C, foldl1S, f)
foldl1E :: (Monad m, MonoFoldable mono, a ~ Element mono)
=> (a -> a -> a)
-> ConduitT mono o m (Maybe a)
INLINE_RULE(foldl1E, f, foldl (foldMaybeNull f) Nothing)
foldMaybeNull :: (MonoFoldable mono, e ~ Element mono)
=> (e -> e -> e)
-> Maybe e
-> mono
-> Maybe e
foldMaybeNull :: forall mono e.
(MonoFoldable mono, e ~ Element mono) =>
(e -> e -> e) -> Maybe e -> mono -> Maybe e
foldMaybeNull e -> e -> e
f Maybe e
macc mono
mono =
case (Maybe e
macc, mono -> Maybe (NonNull mono)
forall mono. MonoFoldable mono => mono -> Maybe (NonNull mono)
NonNull.fromNullable mono
mono) of
(Just e
acc, Just NonNull mono
nn) -> e -> Maybe e
forall a. a -> Maybe a
Just (e -> Maybe e) -> e -> Maybe e
forall a b. (a -> b) -> a -> b
$ (e -> Element (NonNull mono) -> e) -> e -> NonNull mono -> e
forall mono a.
MonoFoldable mono =>
(a -> Element mono -> a) -> a -> mono -> a
forall a.
(a -> Element (NonNull mono) -> a) -> a -> NonNull mono -> a
ofoldl' e -> e -> e
e -> Element (NonNull mono) -> e
f e
acc NonNull mono
nn
(Maybe e
Nothing, Just NonNull mono
nn) -> e -> Maybe e
forall a. a -> Maybe a
Just (e -> Maybe e) -> e -> Maybe e
forall a b. (a -> b) -> a -> b
$ (Element mono -> Element mono -> Element mono)
-> NonNull mono -> Element mono
forall mono.
MonoFoldable mono =>
(Element mono -> Element mono -> Element mono)
-> NonNull mono -> Element mono
NonNull.ofoldl1' e -> e -> e
Element mono -> Element mono -> Element mono
f NonNull mono
nn
(Maybe e, Maybe (NonNull mono))
_ -> Maybe e
macc
{-# INLINE foldMaybeNull #-}
all, allC :: Monad m
=> (a -> Bool)
-> ConduitT a o m Bool
allC :: forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m Bool
allC a -> Bool
f = (Maybe a -> Bool)
-> ConduitT a o m (Maybe a) -> ConduitT a o m Bool
forall a b. (a -> b) -> ConduitT a o m a -> ConduitT a o m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe a -> Bool
forall a. Maybe a -> Bool
isNothing (ConduitT a o m (Maybe a) -> ConduitT a o m Bool)
-> ConduitT a o m (Maybe a) -> ConduitT a o m Bool
forall a b. (a -> b) -> a -> b
$ (a -> Bool) -> ConduitT a o m (Maybe a)
forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m (Maybe a)
find (Bool -> Bool
Prelude.not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> Bool
f)
{-# INLINE allC #-}
STREAMING(all, allC, allS, f)
allE :: (Monad m, MonoFoldable mono)
=> (Element mono -> Bool)
-> ConduitT mono o m Bool
INLINE_RULE(allE, f, all (oall f))
any, anyC :: Monad m
=> (a -> Bool)
-> ConduitT a o m Bool
anyC :: forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m Bool
anyC = (Maybe a -> Bool)
-> ConduitT a o m (Maybe a) -> ConduitT a o m Bool
forall a b. (a -> b) -> ConduitT a o m a -> ConduitT a o m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe a -> Bool
forall a. Maybe a -> Bool
isJust (ConduitT a o m (Maybe a) -> ConduitT a o m Bool)
-> ((a -> Bool) -> ConduitT a o m (Maybe a))
-> (a -> Bool)
-> ConduitT a o m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (a -> Bool) -> ConduitT a o m (Maybe a)
forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m (Maybe a)
find
{-# INLINE anyC #-}
STREAMING(any, anyC, anyS, f)
anyE :: (Monad m, MonoFoldable mono)
=> (Element mono -> Bool)
-> ConduitT mono o m Bool
INLINE_RULE(anyE, f, any (oany f))
and :: Monad m => ConduitT Bool o m Bool
INLINE_RULE0(and, all id)
andE :: (Monad m, MonoFoldable mono, Element mono ~ Bool)
=> ConduitT mono o m Bool
INLINE_RULE0(andE, allE id)
or :: Monad m => ConduitT Bool o m Bool
INLINE_RULE0(or, any id)
orE :: (Monad m, MonoFoldable mono, Element mono ~ Bool)
=> ConduitT mono o m Bool
INLINE_RULE0(orE, anyE id)
asum :: (Monad m, Alternative f)
=> ConduitT (f a) o m (f a)
INLINE_RULE0(asum, foldl (<|>) empty)
elem :: (Monad m, Eq a) => a -> ConduitT a o m Bool
INLINE_RULE(elem, x, any (== x))
elemE :: (Monad m, Seq.IsSequence seq, Eq (Element seq))
=> Element seq
-> ConduitT seq o m Bool
INLINE_RULE(elemE, f, any (oelem f))
notElem :: (Monad m, Eq a) => a -> ConduitT a o m Bool
INLINE_RULE(notElem, x, all (/= x))
notElemE :: (Monad m, Seq.IsSequence seq, Eq (Element seq))
=> Element seq
-> ConduitT seq o m Bool
INLINE_RULE(notElemE, x, all (onotElem x))
sinkLazy, sinkLazyC :: (Monad m, LazySequence lazy strict)
=> ConduitT strict o m lazy
sinkLazyC :: forall (m :: * -> *) lazy strict o.
(Monad m, LazySequence lazy strict) =>
ConduitT strict o m lazy
sinkLazyC = ([strict] -> lazy
forall lazy strict. LazySequence lazy strict => [strict] -> lazy
fromChunks ([strict] -> lazy)
-> (([strict] -> [strict]) -> [strict])
-> ([strict] -> [strict])
-> lazy
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (([strict] -> [strict]) -> [strict] -> [strict]
forall a b. (a -> b) -> a -> b
$ [])) (([strict] -> [strict]) -> lazy)
-> ConduitT strict o m ([strict] -> [strict])
-> ConduitT strict o m lazy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (([strict] -> [strict]) -> strict -> [strict] -> [strict])
-> ([strict] -> [strict])
-> ConduitT strict o m ([strict] -> [strict])
forall (m :: * -> *) b a o.
Monad m =>
(b -> a -> b) -> b -> ConduitT a o m b
CL.fold (\[strict] -> [strict]
front strict
next -> [strict] -> [strict]
front ([strict] -> [strict])
-> ([strict] -> [strict]) -> [strict] -> [strict]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (strict
nextstrict -> [strict] -> [strict]
forall a. a -> [a] -> [a]
:)) [strict] -> [strict]
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
{-# INLINE sinkLazyC #-}
STREAMING0(sinkLazy, sinkLazyC, sinkLazyS)
sinkList :: Monad m => ConduitT a o m [a]
INLINE_RULE0(sinkList, CL.consume)
sinkVector, sinkVectorC :: (V.Vector v a, PrimMonad m)
=> ConduitT a o m (v a)
sinkVectorC :: forall (v :: * -> *) a (m :: * -> *) o.
(Vector v a, PrimMonad m) =>
ConduitT a o m (v a)
sinkVectorC = do
let initSize :: a
initSize = a
10
Mutable v (PrimState m) a
mv0 <- Int -> ConduitT a o m (Mutable v (PrimState (ConduitT a o m)) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VM.new Int
forall {a}. Num a => a
initSize
let go :: Int -> Int -> Mutable v (PrimState m) a -> ConduitT a o m (v a)
go Int
maxSize Int
i Mutable v (PrimState m) a
mv | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
maxSize = do
let newMax :: Int
newMax = Int
maxSize Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2
Mutable v (PrimState m) a
mv' <- Mutable v (PrimState (ConduitT a o m)) a
-> Int -> ConduitT a o m (Mutable v (PrimState (ConduitT a o m)) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> m (v (PrimState m) a)
VM.grow Mutable v (PrimState m) a
Mutable v (PrimState (ConduitT a o m)) a
mv Int
maxSize
Int -> Int -> Mutable v (PrimState m) a -> ConduitT a o m (v a)
go Int
newMax Int
i Mutable v (PrimState m) a
mv'
go Int
maxSize Int
i Mutable v (PrimState m) a
mv = do
Maybe a
mx <- ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
case Maybe a
mx of
Maybe a
Nothing -> Int -> Int -> v a -> v a
forall (v :: * -> *) a.
(HasCallStack, Vector v a) =>
Int -> Int -> v a -> v a
V.slice Int
0 Int
i (v a -> v a) -> ConduitT a o m (v a) -> ConduitT a o m (v a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mutable v (PrimState (ConduitT a o m)) a -> ConduitT a o m (v a)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState m) a
Mutable v (PrimState (ConduitT a o m)) a
mv
Just a
x -> do
Mutable v (PrimState (ConduitT a o m)) a
-> Int -> a -> ConduitT a o m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VM.write Mutable v (PrimState m) a
Mutable v (PrimState (ConduitT a o m)) a
mv Int
i a
x
Int -> Int -> Mutable v (PrimState m) a -> ConduitT a o m (v a)
go Int
maxSize (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Mutable v (PrimState m) a
mv
Int -> Int -> Mutable v (PrimState m) a -> ConduitT a o m (v a)
forall {m :: * -> *} {v :: * -> *} {a} {o}.
(PrimMonad m, Vector v a) =>
Int -> Int -> Mutable v (PrimState m) a -> ConduitT a o m (v a)
go Int
forall {a}. Num a => a
initSize Int
0 Mutable v (PrimState m) a
mv0
{-# INLINEABLE sinkVectorC #-}
STREAMING0(sinkVector, sinkVectorC, sinkVectorS)
sinkVectorN, sinkVectorNC :: (V.Vector v a, PrimMonad m)
=> Int
-> ConduitT a o m (v a)
sinkVectorNC :: forall (v :: * -> *) a (m :: * -> *) o.
(Vector v a, PrimMonad m) =>
Int -> ConduitT a o m (v a)
sinkVectorNC Int
maxSize = do
Mutable v (PrimState m) a
mv <- Int -> ConduitT a o m (Mutable v (PrimState (ConduitT a o m)) a)
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VM.new Int
maxSize
let go :: Int -> ConduitT a o m (v a)
go Int
i | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
maxSize = Mutable v (PrimState (ConduitT a o m)) a -> ConduitT a o m (v a)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState m) a
Mutable v (PrimState (ConduitT a o m)) a
mv
go Int
i = do
Maybe a
mx <- ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
case Maybe a
mx of
Maybe a
Nothing -> Int -> Int -> v a -> v a
forall (v :: * -> *) a.
(HasCallStack, Vector v a) =>
Int -> Int -> v a -> v a
V.slice Int
0 Int
i (v a -> v a) -> ConduitT a o m (v a) -> ConduitT a o m (v a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mutable v (PrimState (ConduitT a o m)) a -> ConduitT a o m (v a)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState m) a
Mutable v (PrimState (ConduitT a o m)) a
mv
Just a
x -> do
Mutable v (PrimState (ConduitT a o m)) a
-> Int -> a -> ConduitT a o m ()
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VM.write Mutable v (PrimState m) a
Mutable v (PrimState (ConduitT a o m)) a
mv Int
i a
x
Int -> ConduitT a o m (v a)
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Int -> ConduitT a o m (v a)
go Int
0
{-# INLINEABLE sinkVectorNC #-}
STREAMING(sinkVectorN, sinkVectorNC, sinkVectorNS, maxSize)
sinkLazyBuilder, sinkLazyBuilderC :: Monad m => ConduitT Builder o m BL.ByteString
sinkLazyBuilderC :: forall (m :: * -> *) o. Monad m => ConduitT Builder o m ByteString
sinkLazyBuilderC = (Builder -> ByteString)
-> ConduitT Builder o m Builder -> ConduitT Builder o m ByteString
forall a b.
(a -> b) -> ConduitT Builder o m a -> ConduitT Builder o m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Builder -> ByteString
toLazyByteString ConduitT Builder o m Builder
forall (m :: * -> *) a o. (Monad m, Monoid a) => ConduitT a o m a
fold
{-# INLINE sinkLazyBuilderC #-}
STREAMING0(sinkLazyBuilder, sinkLazyBuilderC, sinkLazyBuilderS)
sinkNull :: Monad m => ConduitT a o m ()
INLINE_RULE0(sinkNull, CL.sinkNull)
awaitNonNull :: (Monad m, MonoFoldable a) => ConduitT a o m (Maybe (NonNull.NonNull a))
awaitNonNull :: forall (m :: * -> *) a o.
(Monad m, MonoFoldable a) =>
ConduitT a o m (Maybe (NonNull a))
awaitNonNull =
ConduitT a o m (Maybe (NonNull a))
forall (m :: * -> *) a o.
(Monad m, MonoFoldable a) =>
ConduitT a o m (Maybe (NonNull a))
go
where
go :: ConduitT i o m (Maybe (NonNull i))
go = ConduitT i o m (Maybe i)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT i o m (Maybe i)
-> (Maybe i -> ConduitT i o m (Maybe (NonNull i)))
-> ConduitT i o m (Maybe (NonNull i))
forall a b.
ConduitT i o m a -> (a -> ConduitT i o m b) -> ConduitT i o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT i o m (Maybe (NonNull i))
-> (i -> ConduitT i o m (Maybe (NonNull i)))
-> Maybe i
-> ConduitT i o m (Maybe (NonNull i))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (NonNull i) -> ConduitT i o m (Maybe (NonNull i))
forall a. a -> ConduitT i o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (NonNull i)
forall a. Maybe a
Nothing) i -> ConduitT i o m (Maybe (NonNull i))
go'
go' :: i -> ConduitT i o m (Maybe (NonNull i))
go' = ConduitT i o m (Maybe (NonNull i))
-> (NonNull i -> ConduitT i o m (Maybe (NonNull i)))
-> Maybe (NonNull i)
-> ConduitT i o m (Maybe (NonNull i))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ConduitT i o m (Maybe (NonNull i))
go (Maybe (NonNull i) -> ConduitT i o m (Maybe (NonNull i))
forall a. a -> ConduitT i o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (NonNull i) -> ConduitT i o m (Maybe (NonNull i)))
-> (NonNull i -> Maybe (NonNull i))
-> NonNull i
-> ConduitT i o m (Maybe (NonNull i))
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NonNull i -> Maybe (NonNull i)
forall a. a -> Maybe a
Just) (Maybe (NonNull i) -> ConduitT i o m (Maybe (NonNull i)))
-> (i -> Maybe (NonNull i))
-> i
-> ConduitT i o m (Maybe (NonNull i))
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. i -> Maybe (NonNull i)
forall mono. MonoFoldable mono => mono -> Maybe (NonNull mono)
NonNull.fromNullable
{-# INLINE awaitNonNull #-}
head :: Monad m => ConduitT a o m (Maybe a)
head :: forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
head = ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
CL.head
headDef :: Monad m => a -> ConduitT a o m a
headDef :: forall (m :: * -> *) a o. Monad m => a -> ConduitT a o m a
headDef a
a = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
a (Maybe a -> a) -> ConduitT a o m (Maybe a) -> ConduitT a o m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
head
headE :: (Monad m, Seq.IsSequence seq) => ConduitT seq o m (Maybe (Element seq))
headE :: forall (m :: * -> *) seq o.
(Monad m, IsSequence seq) =>
ConduitT seq o m (Maybe (Element seq))
headE =
ConduitT seq o m (Maybe (Element seq))
forall (m :: * -> *) seq o.
(Monad m, IsSequence seq) =>
ConduitT seq o m (Maybe (Element seq))
loop
where
loop :: ConduitT mono o m (Maybe (Element mono))
loop = ConduitT mono o m (Maybe mono)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT mono o m (Maybe mono)
-> (Maybe mono -> ConduitT mono o m (Maybe (Element mono)))
-> ConduitT mono o m (Maybe (Element mono))
forall a b.
ConduitT mono o m a
-> (a -> ConduitT mono o m b) -> ConduitT mono o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT mono o m (Maybe (Element mono))
-> (mono -> ConduitT mono o m (Maybe (Element mono)))
-> Maybe mono
-> ConduitT mono o m (Maybe (Element mono))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono))
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Element mono)
forall a. Maybe a
Nothing) mono -> ConduitT mono o m (Maybe (Element mono))
go
go :: mono -> ConduitT mono o m (Maybe (Element mono))
go mono
x =
case mono -> Maybe (Element mono, mono)
forall seq. IsSequence seq => seq -> Maybe (Element seq, seq)
Seq.uncons mono
x of
Maybe (Element mono, mono)
Nothing -> ConduitT mono o m (Maybe (Element mono))
loop
Just (Element mono
y, mono
z) -> do
Bool -> ConduitT mono o m () -> ConduitT mono o m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (mono -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull mono
z) (ConduitT mono o m () -> ConduitT mono o m ())
-> ConduitT mono o m () -> ConduitT mono o m ()
forall a b. (a -> b) -> a -> b
$ mono -> ConduitT mono o m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
z
Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono))
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono)))
-> Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono))
forall a b. (a -> b) -> a -> b
$ Element mono -> Maybe (Element mono)
forall a. a -> Maybe a
Just Element mono
y
{-# INLINE headE #-}
peek :: Monad m => ConduitT a o m (Maybe a)
peek :: forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
peek = ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
CL.peek
{-# INLINE peek #-}
peekE :: (Monad m, MonoFoldable mono) => ConduitT mono o m (Maybe (Element mono))
peekE :: forall (m :: * -> *) mono o.
(Monad m, MonoFoldable mono) =>
ConduitT mono o m (Maybe (Element mono))
peekE =
ConduitT mono o m (Maybe (Element mono))
forall (m :: * -> *) mono o.
(Monad m, MonoFoldable mono) =>
ConduitT mono o m (Maybe (Element mono))
loop
where
loop :: ConduitT mono o m (Maybe (Element mono))
loop = ConduitT mono o m (Maybe mono)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT mono o m (Maybe mono)
-> (Maybe mono -> ConduitT mono o m (Maybe (Element mono)))
-> ConduitT mono o m (Maybe (Element mono))
forall a b.
ConduitT mono o m a
-> (a -> ConduitT mono o m b) -> ConduitT mono o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT mono o m (Maybe (Element mono))
-> (mono -> ConduitT mono o m (Maybe (Element mono)))
-> Maybe mono
-> ConduitT mono o m (Maybe (Element mono))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono))
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Element mono)
forall a. Maybe a
Nothing) mono -> ConduitT mono o m (Maybe (Element mono))
go
go :: mono -> ConduitT mono o m (Maybe (Element mono))
go mono
x =
case mono -> Maybe (Element mono)
forall mono. MonoFoldable mono => mono -> Maybe (Element mono)
headMay mono
x of
Maybe (Element mono)
Nothing -> ConduitT mono o m (Maybe (Element mono))
loop
Just Element mono
y -> do
mono -> ConduitT mono o m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
x
Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono))
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono)))
-> Maybe (Element mono) -> ConduitT mono o m (Maybe (Element mono))
forall a b. (a -> b) -> a -> b
$ Element mono -> Maybe (Element mono)
forall a. a -> Maybe a
Just Element mono
y
{-# INLINE peekE #-}
last, lastC :: Monad m => ConduitT a o m (Maybe a)
lastC :: forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
lastC =
ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a o m (Maybe a)
-> (Maybe a -> ConduitT a o m (Maybe a))
-> ConduitT a o m (Maybe a)
forall a b.
ConduitT a o m a -> (a -> ConduitT a o m b) -> ConduitT a o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a o m (Maybe a)
-> (a -> ConduitT a o m (Maybe a))
-> Maybe a
-> ConduitT a o m (Maybe a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe a -> ConduitT a o m (Maybe a)
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing) a -> ConduitT a o m (Maybe a)
forall {m :: * -> *} {i} {o}.
Monad m =>
i -> ConduitT i o m (Maybe i)
loop
where
loop :: i -> ConduitT i o m (Maybe i)
loop i
prev = ConduitT i o m (Maybe i)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT i o m (Maybe i)
-> (Maybe i -> ConduitT i o m (Maybe i))
-> ConduitT i o m (Maybe i)
forall a b.
ConduitT i o m a -> (a -> ConduitT i o m b) -> ConduitT i o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT i o m (Maybe i)
-> (i -> ConduitT i o m (Maybe i))
-> Maybe i
-> ConduitT i o m (Maybe i)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe i -> ConduitT i o m (Maybe i)
forall a. a -> ConduitT i o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe i -> ConduitT i o m (Maybe i))
-> Maybe i -> ConduitT i o m (Maybe i)
forall a b. (a -> b) -> a -> b
$ i -> Maybe i
forall a. a -> Maybe a
Just i
prev) i -> ConduitT i o m (Maybe i)
loop
STREAMING0(last, lastC, lastS)
lastDef :: Monad m => a -> ConduitT a o m a
lastDef :: forall (m :: * -> *) a o. Monad m => a -> ConduitT a o m a
lastDef a
a = a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
a (Maybe a -> a) -> ConduitT a o m (Maybe a) -> ConduitT a o m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
last
lastE, lastEC :: (Monad m, Seq.IsSequence seq) => ConduitT seq o m (Maybe (Element seq))
lastEC :: forall (m :: * -> *) seq o.
(Monad m, IsSequence seq) =>
ConduitT seq o m (Maybe (Element seq))
lastEC =
ConduitT seq o m (Maybe (NonNull seq))
forall (m :: * -> *) a o.
(Monad m, MonoFoldable a) =>
ConduitT a o m (Maybe (NonNull a))
awaitNonNull ConduitT seq o m (Maybe (NonNull seq))
-> (Maybe (NonNull seq) -> ConduitT seq o m (Maybe (Element seq)))
-> ConduitT seq o m (Maybe (Element seq))
forall a b.
ConduitT seq o m a
-> (a -> ConduitT seq o m b) -> ConduitT seq o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT seq o m (Maybe (Element seq))
-> (NonNull seq -> ConduitT seq o m (Maybe (Element seq)))
-> Maybe (NonNull seq)
-> ConduitT seq o m (Maybe (Element seq))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (Element seq) -> ConduitT seq o m (Maybe (Element seq))
forall a. a -> ConduitT seq o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Element seq)
forall a. Maybe a
Nothing) (Element seq -> ConduitT seq o m (Maybe (Element seq))
forall {m :: * -> *} {a} {o}.
(Monad m, MonoFoldable a) =>
Element a -> ConduitT a o m (Maybe (Element a))
loop (Element seq -> ConduitT seq o m (Maybe (Element seq)))
-> (NonNull seq -> Element seq)
-> NonNull seq
-> ConduitT seq o m (Maybe (Element seq))
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NonNull seq -> Element seq
forall mono. MonoFoldable mono => NonNull mono -> Element mono
NonNull.last)
where
loop :: Element a -> ConduitT a o m (Maybe (Element a))
loop Element a
prev = ConduitT a o m (Maybe (NonNull a))
forall (m :: * -> *) a o.
(Monad m, MonoFoldable a) =>
ConduitT a o m (Maybe (NonNull a))
awaitNonNull ConduitT a o m (Maybe (NonNull a))
-> (Maybe (NonNull a) -> ConduitT a o m (Maybe (Element a)))
-> ConduitT a o m (Maybe (Element a))
forall a b.
ConduitT a o m a -> (a -> ConduitT a o m b) -> ConduitT a o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a o m (Maybe (Element a))
-> (NonNull a -> ConduitT a o m (Maybe (Element a)))
-> Maybe (NonNull a)
-> ConduitT a o m (Maybe (Element a))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (Element a) -> ConduitT a o m (Maybe (Element a))
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Element a) -> ConduitT a o m (Maybe (Element a)))
-> Maybe (Element a) -> ConduitT a o m (Maybe (Element a))
forall a b. (a -> b) -> a -> b
$ Element a -> Maybe (Element a)
forall a. a -> Maybe a
Just Element a
prev) (Element a -> ConduitT a o m (Maybe (Element a))
loop (Element a -> ConduitT a o m (Maybe (Element a)))
-> (NonNull a -> Element a)
-> NonNull a
-> ConduitT a o m (Maybe (Element a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. NonNull a -> Element a
forall mono. MonoFoldable mono => NonNull mono -> Element mono
NonNull.last)
STREAMING0(lastE, lastEC, lastES)
length :: (Monad m, Num len) => ConduitT a o m len
INLINE_RULE0(length, foldl (\x _ -> x + 1) 0)
lengthE :: (Monad m, Num len, MonoFoldable mono) => ConduitT mono o m len
INLINE_RULE0(lengthE, foldl (\x y -> x + fromIntegral (olength y)) 0)
lengthIf :: (Monad m, Num len) => (a -> Bool) -> ConduitT a o m len
INLINE_RULE(lengthIf, f, foldl (\cnt a -> if f a then (cnt + 1) else cnt) 0)
lengthIfE :: (Monad m, Num len, MonoFoldable mono)
=> (Element mono -> Bool) -> ConduitT mono o m len
INLINE_RULE(lengthIfE, f, foldlE (\cnt a -> if f a then (cnt + 1) else cnt) 0)
maximum :: (Monad m, Ord a) => ConduitT a o m (Maybe a)
INLINE_RULE0(maximum, foldl1 max)
maximumE :: (Monad m, Seq.IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq))
INLINE_RULE0(maximumE, foldl1E max)
minimum :: (Monad m, Ord a) => ConduitT a o m (Maybe a)
INLINE_RULE0(minimum, foldl1 min)
minimumE :: (Monad m, Seq.IsSequence seq, Ord (Element seq)) => ConduitT seq o m (Maybe (Element seq))
INLINE_RULE0(minimumE, foldl1E min)
null :: Monad m => ConduitT a o m Bool
null :: forall (m :: * -> *) a o. Monad m => ConduitT a o m Bool
null = (Bool -> (a -> Bool) -> Maybe a -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (\a
_ -> Bool
False)) (Maybe a -> Bool)
-> ConduitT a o m (Maybe a) -> ConduitT a o m Bool
forall a b. (a -> b) -> ConduitT a o m a -> ConduitT a o m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
peek
{-# INLINE null #-}
nullE :: (Monad m, MonoFoldable mono)
=> ConduitT mono o m Bool
nullE :: forall (m :: * -> *) mono o.
(Monad m, MonoFoldable mono) =>
ConduitT mono o m Bool
nullE =
ConduitT mono o m Bool
forall (m :: * -> *) mono o.
(Monad m, MonoFoldable mono) =>
ConduitT mono o m Bool
go
where
go :: ConduitT mono o m Bool
go = ConduitT mono o m (Maybe mono)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT mono o m (Maybe mono)
-> (Maybe mono -> ConduitT mono o m Bool) -> ConduitT mono o m Bool
forall a b.
ConduitT mono o m a
-> (a -> ConduitT mono o m b) -> ConduitT mono o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT mono o m Bool
-> (mono -> ConduitT mono o m Bool)
-> Maybe mono
-> ConduitT mono o m Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> ConduitT mono o m Bool
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True) mono -> ConduitT mono o m Bool
go'
go' :: mono -> ConduitT mono o m Bool
go' mono
x = if mono -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull mono
x then ConduitT mono o m Bool
go else mono -> ConduitT mono o m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
x ConduitT mono o m ()
-> ConduitT mono o m Bool -> ConduitT mono o m Bool
forall a b.
ConduitT mono o m a -> ConduitT mono o m b -> ConduitT mono o m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> ConduitT mono o m Bool
forall a. a -> ConduitT mono o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
{-# INLINE nullE #-}
sum :: (Monad m, Num a) => ConduitT a o m a
INLINE_RULE0(sum, foldl (+) 0)
sumE :: (Monad m, MonoFoldable mono, Num (Element mono)) => ConduitT mono o m (Element mono)
INLINE_RULE0(sumE, foldlE (+) 0)
product :: (Monad m, Num a) => ConduitT a o m a
INLINE_RULE0(product, foldl (*) 1)
productE :: (Monad m, MonoFoldable mono, Num (Element mono)) => ConduitT mono o m (Element mono)
INLINE_RULE0(productE, foldlE (*) 1)
find, findC :: Monad m => (a -> Bool) -> ConduitT a o m (Maybe a)
findC :: forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m (Maybe a)
findC a -> Bool
f =
ConduitT a o m (Maybe a)
loop
where
loop :: ConduitT a o m (Maybe a)
loop = ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a o m (Maybe a)
-> (Maybe a -> ConduitT a o m (Maybe a))
-> ConduitT a o m (Maybe a)
forall a b.
ConduitT a o m a -> (a -> ConduitT a o m b) -> ConduitT a o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a o m (Maybe a)
-> (a -> ConduitT a o m (Maybe a))
-> Maybe a
-> ConduitT a o m (Maybe a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe a -> ConduitT a o m (Maybe a)
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing) a -> ConduitT a o m (Maybe a)
go
go :: a -> ConduitT a o m (Maybe a)
go a
x = if a -> Bool
f a
x then Maybe a -> ConduitT a o m (Maybe a)
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Maybe a
forall a. a -> Maybe a
Just a
x) else ConduitT a o m (Maybe a)
loop
{-# INLINE findC #-}
STREAMING(find, findC, findS, f)
mapM_ :: Monad m => (a -> m ()) -> ConduitT a o m ()
INLINE_RULE(mapM_, f, CL.mapM_ f)
mapM_E :: (Monad m, MonoFoldable mono) => (Element mono -> m ()) -> ConduitT mono o m ()
INLINE_RULE(mapM_E, f, CL.mapM_ (omapM_ f))
foldM :: Monad m => (a -> b -> m a) -> a -> ConduitT b o m a
INLINE_RULE(foldM, f x, CL.foldM f x)
foldME :: (Monad m, MonoFoldable mono)
=> (a -> Element mono -> m a)
-> a
-> ConduitT mono o m a
INLINE_RULE(foldME, f x, foldM (ofoldlM f) x)
foldMapM :: (Monad m, Monoid w) => (a -> m w) -> ConduitT a o m w
INLINE_RULE(foldMapM, f, CL.foldMapM f)
foldMapME :: (Monad m, MonoFoldable mono, Monoid w)
=> (Element mono -> m w)
-> ConduitT mono o m w
INLINE_RULE(foldMapME, f, CL.foldM (ofoldlM (\accum e -> mappend accum `liftM` f e)) mempty)
sinkFileBS :: MonadResource m => FilePath -> ConduitT ByteString o m ()
sinkFileBS :: forall (m :: * -> *) o.
MonadResource m =>
FilePath -> ConduitT ByteString o m ()
sinkFileBS = FilePath -> ConduitT ByteString o m ()
forall (m :: * -> *) o.
MonadResource m =>
FilePath -> ConduitT ByteString o m ()
sinkFile
{-# INLINE sinkFileBS #-}
print :: (Show a, MonadIO m) => ConduitT a o m ()
INLINE_RULE0(print, mapM_ (liftIO . Prelude.print))
stdout :: MonadIO m => ConduitT ByteString o m ()
INLINE_RULE0(stdout, sinkHandle IO.stdout)
stderr :: MonadIO m => ConduitT ByteString o m ()
INLINE_RULE0(stderr, sinkHandle IO.stderr)
map :: Monad m => (a -> b) -> ConduitT a b m ()
INLINE_RULE(map, f, CL.map f)
mapE :: (Monad m, Functor f) => (a -> b) -> ConduitT (f a) (f b) m ()
INLINE_RULE(mapE, f, CL.map (fmap f))
omapE :: (Monad m, MonoFunctor mono) => (Element mono -> Element mono) -> ConduitT mono mono m ()
INLINE_RULE(omapE, f, CL.map (omap f))
concatMap, concatMapC :: (Monad m, MonoFoldable mono)
=> (a -> mono)
-> ConduitT a (Element mono) m ()
concatMapC :: forall (m :: * -> *) mono a.
(Monad m, MonoFoldable mono) =>
(a -> mono) -> ConduitT a (Element mono) m ()
concatMapC a -> mono
f = (a -> ConduitT a (Element mono) m ())
-> ConduitT a (Element mono) m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (mono -> ConduitT a (Element mono) m ()
forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldMany (mono -> ConduitT a (Element mono) m ())
-> (a -> mono) -> a -> ConduitT a (Element mono) m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> mono
f)
{-# INLINE concatMapC #-}
STREAMING(concatMap, concatMapC, concatMapS, f)
concatMapE :: (Monad m, MonoFoldable mono, Monoid w)
=> (Element mono -> w)
-> ConduitT mono w m ()
INLINE_RULE(concatMapE, f, CL.map (ofoldMap f))
take :: Monad m => Int -> ConduitT a a m ()
INLINE_RULE(take, n, CL.isolate n)
takeE :: (Monad m, Seq.IsSequence seq)
=> Seq.Index seq
-> ConduitT seq seq m ()
takeE :: forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
takeE =
Index seq -> ConduitT seq seq m ()
forall {mono} {m :: * -> *}.
(Monad m, IsSequence mono) =>
Index mono -> ConduitT mono mono m ()
loop
where
loop :: Index mono -> ConduitT mono mono m ()
loop Index mono
i = if Index mono
i Index mono -> Index mono -> Bool
forall a. Ord a => a -> a -> Bool
<= Index mono
0
then () -> ConduitT mono mono m ()
forall a. a -> ConduitT mono mono m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else ConduitT mono mono m (Maybe mono)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT mono mono m (Maybe mono)
-> (Maybe mono -> ConduitT mono mono m ())
-> ConduitT mono mono m ()
forall a b.
ConduitT mono mono m a
-> (a -> ConduitT mono mono m b) -> ConduitT mono mono m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT mono mono m ()
-> (mono -> ConduitT mono mono m ())
-> Maybe mono
-> ConduitT mono mono m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT mono mono m ()
forall a. a -> ConduitT mono mono m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Index mono -> mono -> ConduitT mono mono m ()
go Index mono
i)
go :: Index mono -> mono -> ConduitT mono mono m ()
go Index mono
i mono
sq = do
Bool -> ConduitT mono mono m () -> ConduitT mono mono m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (mono -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull mono
x) (ConduitT mono mono m () -> ConduitT mono mono m ())
-> ConduitT mono mono m () -> ConduitT mono mono m ()
forall a b. (a -> b) -> a -> b
$ mono -> ConduitT mono mono m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield mono
x
Bool -> ConduitT mono mono m () -> ConduitT mono mono m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (mono -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull mono
y) (ConduitT mono mono m () -> ConduitT mono mono m ())
-> ConduitT mono mono m () -> ConduitT mono mono m ()
forall a b. (a -> b) -> a -> b
$ mono -> ConduitT mono mono m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
y
Index mono -> ConduitT mono mono m ()
loop Index mono
i'
where
(mono
x, mono
y) = Index mono -> mono -> (mono, mono)
forall seq. IsSequence seq => Index seq -> seq -> (seq, seq)
Seq.splitAt Index mono
i mono
sq
i' :: Index mono
i' = Index mono
i Index mono -> Index mono -> Index mono
forall a. Num a => a -> a -> a
- Int -> Index mono
forall a b. (Integral a, Num b) => a -> b
fromIntegral (mono -> Int
forall mono. MonoFoldable mono => mono -> Int
olength mono
x)
{-# INLINEABLE takeE #-}
takeWhile :: Monad m
=> (a -> Bool)
-> ConduitT a a m ()
takeWhile :: forall (m :: * -> *) a. Monad m => (a -> Bool) -> ConduitT a a m ()
takeWhile a -> Bool
f =
ConduitT a a m ()
loop
where
loop :: ConduitT a a m ()
loop = ConduitT a a m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a a m (Maybe a)
-> (Maybe a -> ConduitT a a m ()) -> ConduitT a a m ()
forall a b.
ConduitT a a m a -> (a -> ConduitT a a m b) -> ConduitT a a m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a a m ()
-> (a -> ConduitT a a m ()) -> Maybe a -> ConduitT a a m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT a a m ()
forall a. a -> ConduitT a a m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) a -> ConduitT a a m ()
go
go :: a -> ConduitT a a m ()
go a
x = if a -> Bool
f a
x
then a -> ConduitT a a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
x ConduitT a a m () -> ConduitT a a m () -> ConduitT a a m ()
forall a b.
ConduitT a a m a -> ConduitT a a m b -> ConduitT a a m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT a a m ()
loop
else a -> ConduitT a a m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover a
x
{-# INLINE takeWhile #-}
takeWhileE :: (Monad m, Seq.IsSequence seq)
=> (Element seq -> Bool)
-> ConduitT seq seq m ()
takeWhileE :: forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq seq m ()
takeWhileE Element seq -> Bool
f =
ConduitT seq seq m ()
loop
where
loop :: ConduitT seq seq m ()
loop = ConduitT seq seq m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT seq seq m (Maybe seq)
-> (Maybe seq -> ConduitT seq seq m ()) -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> (a -> ConduitT seq seq m b) -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT seq seq m ()
-> (seq -> ConduitT seq seq m ())
-> Maybe seq
-> ConduitT seq seq m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT seq seq m ()
forall a. a -> ConduitT seq seq m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) seq -> ConduitT seq seq m ()
go
go :: seq -> ConduitT seq seq m ()
go seq
sq = do
Bool -> ConduitT seq seq m () -> ConduitT seq seq m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
x) (ConduitT seq seq m () -> ConduitT seq seq m ())
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b. (a -> b) -> a -> b
$ seq -> ConduitT seq seq m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
x
if seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
y
then ConduitT seq seq m ()
loop
else seq -> ConduitT seq seq m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover seq
y
where
(seq
x, seq
y) = (Element seq -> Bool) -> seq -> (seq, seq)
forall seq.
IsSequence seq =>
(Element seq -> Bool) -> seq -> (seq, seq)
Seq.span Element seq -> Bool
f seq
sq
{-# INLINE takeWhileE #-}
takeExactly :: Monad m
=> Int
-> ConduitT a b m r
-> ConduitT a b m r
takeExactly :: forall (m :: * -> *) a b r.
Monad m =>
Int -> ConduitT a b m r -> ConduitT a b m r
takeExactly Int
count ConduitT a b m r
inner = Int -> ConduitT a a m ()
forall (m :: * -> *) a. Monad m => Int -> ConduitT a a m ()
take Int
count ConduitT a a m () -> ConduitT a b m r -> ConduitT a b m r
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| do
r
r <- ConduitT a b m r
inner
ConduitT a b m ()
forall (m :: * -> *) a o. Monad m => ConduitT a o m ()
CL.sinkNull
r -> ConduitT a b m r
forall a. a -> ConduitT a b m a
forall (m :: * -> *) a. Monad m => a -> m a
return r
r
takeExactlyE :: (Monad m, Seq.IsSequence a)
=> Seq.Index a
-> ConduitT a b m r
-> ConduitT a b m r
takeExactlyE :: forall (m :: * -> *) a b r.
(Monad m, IsSequence a) =>
Index a -> ConduitT a b m r -> ConduitT a b m r
takeExactlyE Index a
count ConduitT a b m r
inner = Index a -> ConduitT a a m ()
forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
takeE Index a
count ConduitT a a m () -> ConduitT a b m r -> ConduitT a b m r
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| do
r
r <- ConduitT a b m r
inner
ConduitT a b m ()
forall (m :: * -> *) a o. Monad m => ConduitT a o m ()
CL.sinkNull
r -> ConduitT a b m r
forall a. a -> ConduitT a b m a
forall (m :: * -> *) a. Monad m => a -> m a
return r
r
{-# INLINE takeExactlyE #-}
concat, concatC :: (Monad m, MonoFoldable mono)
=> ConduitT mono (Element mono) m ()
concatC :: forall (m :: * -> *) mono.
(Monad m, MonoFoldable mono) =>
ConduitT mono (Element mono) m ()
concatC = (mono -> ConduitT mono (Element mono) m ())
-> ConduitT mono (Element mono) m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever mono -> ConduitT mono (Element mono) m ()
forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldMany
STREAMING0(concat, concatC, concatS)
filter :: Monad m => (a -> Bool) -> ConduitT a a m ()
INLINE_RULE(filter, f, CL.filter f)
filterE :: (Seq.IsSequence seq, Monad m) => (Element seq -> Bool) -> ConduitT seq seq m ()
INLINE_RULE(filterE, f, CL.map (Seq.filter f))
mapWhile :: Monad m => (a -> Maybe b) -> ConduitT a b m ()
mapWhile :: forall (m :: * -> *) a b.
Monad m =>
(a -> Maybe b) -> ConduitT a b m ()
mapWhile a -> Maybe b
f =
ConduitT a b m ()
loop
where
loop :: ConduitT a b m ()
loop = ConduitT a b m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a b m (Maybe a)
-> (Maybe a -> ConduitT a b m ()) -> ConduitT a b m ()
forall a b.
ConduitT a b m a -> (a -> ConduitT a b m b) -> ConduitT a b m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a b m ()
-> (a -> ConduitT a b m ()) -> Maybe a -> ConduitT a b m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT a b m ()
forall a. a -> ConduitT a b m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) a -> ConduitT a b m ()
go
go :: a -> ConduitT a b m ()
go a
x =
case a -> Maybe b
f a
x of
Just b
y -> b -> ConduitT a b m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
y ConduitT a b m () -> ConduitT a b m () -> ConduitT a b m ()
forall a b.
ConduitT a b m a -> ConduitT a b m b -> ConduitT a b m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT a b m ()
loop
Maybe b
Nothing -> a -> ConduitT a b m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover a
x
{-# INLINE mapWhile #-}
conduitVector :: (V.Vector v a, PrimMonad m)
=> Int
-> ConduitT a (v a) m ()
conduitVector :: forall (v :: * -> *) a (m :: * -> *).
(Vector v a, PrimMonad m) =>
Int -> ConduitT a (v a) m ()
conduitVector Int
size =
ConduitT a (v a) m ()
loop
where
loop :: ConduitT a (v a) m ()
loop = do
v a
v <- Int -> ConduitT a (v a) m (v a)
forall (v :: * -> *) a (m :: * -> *) o.
(Vector v a, PrimMonad m) =>
Int -> ConduitT a o m (v a)
sinkVectorN Int
size
Bool -> ConduitT a (v a) m () -> ConduitT a (v a) m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (v a -> Bool
forall (v :: * -> *) a. Vector v a => v a -> Bool
V.null v a
v) (ConduitT a (v a) m () -> ConduitT a (v a) m ())
-> ConduitT a (v a) m () -> ConduitT a (v a) m ()
forall a b. (a -> b) -> a -> b
$ do
v a -> ConduitT a (v a) m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield v a
v
ConduitT a (v a) m ()
loop
{-# INLINE conduitVector #-}
scanl, scanlC :: Monad m => (a -> b -> a) -> a -> ConduitT b a m ()
scanlC :: forall (m :: * -> *) a b.
Monad m =>
(a -> b -> a) -> a -> ConduitT b a m ()
scanlC a -> b -> a
f =
a -> ConduitT b a m ()
loop
where
loop :: a -> ConduitT b a m ()
loop a
seed =
ConduitT b a m (Maybe b)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT b a m (Maybe b)
-> (Maybe b -> ConduitT b a m ()) -> ConduitT b a m ()
forall a b.
ConduitT b a m a -> (a -> ConduitT b a m b) -> ConduitT b a m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT b a m ()
-> (b -> ConduitT b a m ()) -> Maybe b -> ConduitT b a m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (a -> ConduitT b a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
seed) b -> ConduitT b a m ()
go
where
go :: b -> ConduitT b a m ()
go b
b = do
let seed' :: a
seed' = a -> b -> a
f a
seed b
b
a
seed' a -> ConduitT b a m () -> ConduitT b a m ()
forall a b. a -> b -> b
`seq` a -> ConduitT b a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
seed
a -> ConduitT b a m ()
loop a
seed'
STREAMING(scanl, scanlC, scanlS, f x)
mapAccumWhile, mapAccumWhileC :: Monad m => (a -> s -> Either s (s, b)) -> s -> ConduitT a b m s
mapAccumWhileC :: forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> Either s (s, b)) -> s -> ConduitT a b m s
mapAccumWhileC a -> s -> Either s (s, b)
f =
s -> ConduitT a b m s
loop
where
loop :: s -> ConduitT a b m s
loop !s
s = ConduitT a b m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a b m (Maybe a)
-> (Maybe a -> ConduitT a b m s) -> ConduitT a b m s
forall a b.
ConduitT a b m a -> (a -> ConduitT a b m b) -> ConduitT a b m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a b m s
-> (a -> ConduitT a b m s) -> Maybe a -> ConduitT a b m s
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (s -> ConduitT a b m s
forall a. a -> ConduitT a b m a
forall (m :: * -> *) a. Monad m => a -> m a
return s
s) a -> ConduitT a b m s
go
where
go :: a -> ConduitT a b m s
go a
a = (s -> ConduitT a b m s)
-> ((s, b) -> ConduitT a b m s)
-> Either s (s, b)
-> ConduitT a b m s
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (s -> ConduitT a b m s
forall a. a -> ConduitT a b m a
forall (m :: * -> *) a. Monad m => a -> m a
return (s -> ConduitT a b m s) -> s -> ConduitT a b m s
forall a b. (a -> b) -> a -> b
$!) (\(s
s', b
b) -> b -> ConduitT a b m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
b ConduitT a b m () -> ConduitT a b m s -> ConduitT a b m s
forall a b.
ConduitT a b m a -> ConduitT a b m b -> ConduitT a b m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> s -> ConduitT a b m s
loop s
s') (Either s (s, b) -> ConduitT a b m s)
-> Either s (s, b) -> ConduitT a b m s
forall a b. (a -> b) -> a -> b
$ a -> s -> Either s (s, b)
f a
a s
s
{-# INLINE mapAccumWhileC #-}
STREAMING(mapAccumWhile, mapAccumWhileC, mapAccumWhileS, f s)
foldWhile :: Monad m => (a -> s -> Either e s) -> s -> ConduitT a o m (Either e s)
foldWhile :: forall (m :: * -> *) a s e o.
Monad m =>
(a -> s -> Either e s) -> s -> ConduitT a o m (Either e s)
foldWhile a -> s -> Either e s
f = s -> ConduitT a o m (Either e s)
loop
where
loop :: s -> ConduitT a o m (Either e s)
loop !s
s = ConduitT a o m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a o m (Maybe a)
-> (Maybe a -> ConduitT a o m (Either e s))
-> ConduitT a o m (Either e s)
forall a b.
ConduitT a o m a -> (a -> ConduitT a o m b) -> ConduitT a o m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a o m (Either e s)
-> (a -> ConduitT a o m (Either e s))
-> Maybe a
-> ConduitT a o m (Either e s)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Either e s -> ConduitT a o m (Either e s)
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either e s -> ConduitT a o m (Either e s))
-> Either e s -> ConduitT a o m (Either e s)
forall a b. (a -> b) -> a -> b
$ s -> Either e s
forall a b. b -> Either a b
Right s
s) a -> ConduitT a o m (Either e s)
go
where
go :: a -> ConduitT a o m (Either e s)
go a
a = (e -> ConduitT a o m (Either e s))
-> (s -> ConduitT a o m (Either e s))
-> Either e s
-> ConduitT a o m (Either e s)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Either e s -> ConduitT a o m (Either e s)
forall a. a -> ConduitT a o m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either e s -> ConduitT a o m (Either e s))
-> (e -> Either e s) -> e -> ConduitT a o m (Either e s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. e -> Either e s
forall a b. a -> Either a b
Left (e -> ConduitT a o m (Either e s))
-> e -> ConduitT a o m (Either e s)
forall a b. (a -> b) -> a -> b
$!) s -> ConduitT a o m (Either e s)
loop (Either e s -> ConduitT a o m (Either e s))
-> Either e s -> ConduitT a o m (Either e s)
forall a b. (a -> b) -> a -> b
$ a -> s -> Either e s
f a
a s
s
{-# INLINE foldWhile #-}
concatMapAccum :: Monad m => (a -> accum -> (accum, [b])) -> accum -> ConduitT a b m ()
INLINE_RULE0(concatMapAccum, CL.concatMapAccum)
intersperse, intersperseC :: Monad m => a -> ConduitT a a m ()
intersperseC :: forall (m :: * -> *) a. Monad m => a -> ConduitT a a m ()
intersperseC a
x =
ConduitT a a m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a a m (Maybe a)
-> (Maybe a -> ConduitT a a m ()) -> ConduitT a a m ()
forall a b.
ConduitT a a m a -> (a -> ConduitT a a m b) -> ConduitT a a m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Element (Maybe a) -> ConduitT a a m ())
-> Maybe a -> ConduitT a a m ()
forall mono (m :: * -> *).
(MonoFoldable mono, Applicative m) =>
(Element mono -> m ()) -> mono -> m ()
forall (m :: * -> *).
Applicative m =>
(Element (Maybe a) -> m ()) -> Maybe a -> m ()
omapM_ a -> ConduitT a a m ()
Element (Maybe a) -> ConduitT a a m ()
go
where
go :: a -> ConduitT a a m ()
go a
y = a -> ConduitT a a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
y ConduitT a a m () -> ConduitT a a m () -> ConduitT a a m ()
forall a b.
ConduitT a a m a -> ConduitT a a m b -> ConduitT a a m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (a -> [a]) -> ConduitT a (Element [a]) m ()
forall (m :: * -> *) mono a.
(Monad m, MonoFoldable mono) =>
(a -> mono) -> ConduitT a (Element mono) m ()
concatMap (\a
z -> [a
x, a
z])
STREAMING(intersperse, intersperseC, intersperseS, x)
slidingWindow, slidingWindowC :: (Monad m, Seq.IsSequence seq, Element seq ~ a) => Int -> ConduitT a seq m ()
slidingWindowC :: forall (m :: * -> *) seq a.
(Monad m, IsSequence seq, Element seq ~ a) =>
Int -> ConduitT a seq m ()
slidingWindowC Int
sz = Int -> seq -> ConduitT (Element seq) seq m ()
forall {m :: * -> *} {t} {t}.
(Monad m, IsSequence t, Num t, Eq t) =>
t -> t -> ConduitT (Element t) t m ()
go (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
sz) seq
forall a. Monoid a => a
mempty
where goContinue :: t -> ConduitT (Element t) t m ()
goContinue t
st = ConduitT (Element t) t m (Maybe (Element t))
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT (Element t) t m (Maybe (Element t))
-> (Maybe (Element t) -> ConduitT (Element t) t m ())
-> ConduitT (Element t) t m ()
forall a b.
ConduitT (Element t) t m a
-> (a -> ConduitT (Element t) t m b) -> ConduitT (Element t) t m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
ConduitT (Element t) t m ()
-> (Element t -> ConduitT (Element t) t m ())
-> Maybe (Element t)
-> ConduitT (Element t) t m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT (Element t) t m ()
forall a. a -> ConduitT (Element t) t m a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
(\Element t
x -> do
let st' :: t
st' = t -> Element t -> t
forall seq. SemiSequence seq => seq -> Element seq -> seq
Seq.snoc t
st Element t
x
t -> ConduitT (Element t) t m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield t
st' ConduitT (Element t) t m ()
-> ConduitT (Element t) t m () -> ConduitT (Element t) t m ()
forall a b.
ConduitT (Element t) t m a
-> ConduitT (Element t) t m b -> ConduitT (Element t) t m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> t -> ConduitT (Element t) t m ()
goContinue (t -> t
forall seq. IsSequence seq => seq -> seq
Seq.unsafeTail t
st')
)
go :: t -> t -> ConduitT (Element t) t m ()
go t
0 t
st = t -> ConduitT (Element t) t m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield t
st ConduitT (Element t) t m ()
-> ConduitT (Element t) t m () -> ConduitT (Element t) t m ()
forall a b.
ConduitT (Element t) t m a
-> ConduitT (Element t) t m b -> ConduitT (Element t) t m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> t -> ConduitT (Element t) t m ()
forall {m :: * -> *} {t}.
(Monad m, IsSequence t) =>
t -> ConduitT (Element t) t m ()
goContinue (t -> t
forall seq. IsSequence seq => seq -> seq
Seq.unsafeTail t
st)
go !t
n t
st = ConduitT (Element t) t m (Maybe (Element t))
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
CL.head ConduitT (Element t) t m (Maybe (Element t))
-> (Maybe (Element t) -> ConduitT (Element t) t m ())
-> ConduitT (Element t) t m ()
forall a b.
ConduitT (Element t) t m a
-> (a -> ConduitT (Element t) t m b) -> ConduitT (Element t) t m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe (Element t)
m ->
case Maybe (Element t)
m of
Maybe (Element t)
Nothing -> t -> ConduitT (Element t) t m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield t
st
Just Element t
x -> t -> t -> ConduitT (Element t) t m ()
go (t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
1) (t -> Element t -> t
forall seq. SemiSequence seq => seq -> Element seq -> seq
Seq.snoc t
st Element t
x)
STREAMING(slidingWindow, slidingWindowC, slidingWindowS, sz)
chunksOfE :: (Monad m, Seq.IsSequence seq) => Seq.Index seq -> ConduitT seq seq m ()
chunksOfE :: forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
chunksOfE Index seq
chunkSize = Index seq -> ConduitT seq seq m ()
forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
chunksOfExactlyE Index seq
chunkSize ConduitT seq seq m ()
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> ConduitT seq seq m b -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (ConduitT seq seq m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT seq seq m (Maybe seq)
-> (Maybe seq -> ConduitT seq seq m ()) -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> (a -> ConduitT seq seq m b) -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT seq seq m ()
-> (seq -> ConduitT seq seq m ())
-> Maybe seq
-> ConduitT seq seq m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT seq seq m ()
forall a. a -> ConduitT seq seq m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) seq -> ConduitT seq seq m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield)
chunksOfExactlyE :: (Monad m, Seq.IsSequence seq) => Seq.Index seq -> ConduitT seq seq m ()
chunksOfExactlyE :: forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
chunksOfExactlyE Index seq
chunkSize = ConduitT seq seq m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT seq seq m (Maybe seq)
-> (Maybe seq -> ConduitT seq seq m ()) -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> (a -> ConduitT seq seq m b) -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT seq seq m ()
-> (seq -> ConduitT seq seq m ())
-> Maybe seq
-> ConduitT seq seq m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT seq seq m ()
forall a. a -> ConduitT seq seq m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) seq -> ConduitT seq seq m ()
start
where
start :: seq -> ConduitT seq seq m ()
start seq
b
| seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
b = Index seq -> ConduitT seq seq m ()
forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
chunksOfExactlyE Index seq
chunkSize
| seq -> Index seq
forall seq. IsSequence seq => seq -> Index seq
Seq.lengthIndex seq
b Index seq -> Index seq -> Bool
forall a. Ord a => a -> a -> Bool
< Index seq
chunkSize = Index seq -> [seq] -> ConduitT seq seq m ()
continue (seq -> Index seq
forall seq. IsSequence seq => seq -> Index seq
Seq.lengthIndex seq
b) [seq
b]
| Bool
otherwise = let (seq
first,seq
rest) = Index seq -> seq -> (seq, seq)
forall seq. IsSequence seq => Index seq -> seq -> (seq, seq)
Seq.splitAt Index seq
chunkSize seq
b in
seq -> ConduitT seq seq m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
first ConduitT seq seq m ()
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> ConduitT seq seq m b -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> seq -> ConduitT seq seq m ()
start seq
rest
continue :: Index seq -> [seq] -> ConduitT seq seq m ()
continue !Index seq
sofar [seq]
bs = do
Maybe seq
next <- ConduitT seq seq m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
case Maybe seq
next of
Maybe seq
Nothing -> seq -> ConduitT seq seq m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover ([seq] -> seq
forall a. Monoid a => [a] -> a
mconcat ([seq] -> seq) -> [seq] -> seq
forall a b. (a -> b) -> a -> b
$ [seq] -> [seq]
forall a. [a] -> [a]
Prelude.reverse [seq]
bs)
Just seq
next' ->
let !sofar' :: Index seq
sofar' = seq -> Index seq
forall seq. IsSequence seq => seq -> Index seq
Seq.lengthIndex seq
next' Index seq -> Index seq -> Index seq
forall a. Num a => a -> a -> a
+ Index seq
sofar
bs' :: [seq]
bs' = seq
next'seq -> [seq] -> [seq]
forall a. a -> [a] -> [a]
:[seq]
bs
in if Index seq
sofar' Index seq -> Index seq -> Bool
forall a. Ord a => a -> a -> Bool
< Index seq
chunkSize
then Index seq -> [seq] -> ConduitT seq seq m ()
continue Index seq
sofar' [seq]
bs'
else seq -> ConduitT seq seq m ()
start ([seq] -> seq
forall a. Monoid a => [a] -> a
mconcat ([seq] -> [seq]
forall a. [a] -> [a]
Prelude.reverse [seq]
bs'))
mapM :: Monad m => (a -> m b) -> ConduitT a b m ()
INLINE_RULE(mapM, f, CL.mapM f)
mapME :: (Monad m, Data.Traversable.Traversable f) => (a -> m b) -> ConduitT (f a) (f b) m ()
INLINE_RULE(mapME, f, CL.mapM (Data.Traversable.mapM f))
omapME :: (Monad m, MonoTraversable mono)
=> (Element mono -> m (Element mono))
-> ConduitT mono mono m ()
INLINE_RULE(omapME, f, CL.mapM (omapM f))
concatMapM, concatMapMC :: (Monad m, MonoFoldable mono)
=> (a -> m mono)
-> ConduitT a (Element mono) m ()
concatMapMC :: forall (m :: * -> *) mono a.
(Monad m, MonoFoldable mono) =>
(a -> m mono) -> ConduitT a (Element mono) m ()
concatMapMC a -> m mono
f = (a -> ConduitT a (Element mono) m ())
-> ConduitT a (Element mono) m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (m mono -> ConduitT a (Element mono) m mono
forall (m :: * -> *) a.
Monad m =>
m a -> ConduitT a (Element mono) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m mono -> ConduitT a (Element mono) m mono)
-> (a -> m mono) -> a -> ConduitT a (Element mono) m mono
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> m mono
f (a -> ConduitT a (Element mono) m mono)
-> (mono -> ConduitT a (Element mono) m ())
-> a
-> ConduitT a (Element mono) m ()
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> mono -> ConduitT a (Element mono) m ()
forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldMany)
STREAMING(concatMapM, concatMapMC, concatMapMS, f)
filterM, filterMC :: Monad m
=> (a -> m Bool)
-> ConduitT a a m ()
filterMC :: forall (m :: * -> *) a.
Monad m =>
(a -> m Bool) -> ConduitT a a m ()
filterMC a -> m Bool
f =
(a -> ConduitT a a m ()) -> ConduitT a a m ()
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever a -> ConduitT a a m ()
go
where
go :: a -> ConduitT a a m ()
go a
x = do
Bool
b <- m Bool -> ConduitT a a m Bool
forall (m :: * -> *) a. Monad m => m a -> ConduitT a a m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m Bool -> ConduitT a a m Bool) -> m Bool -> ConduitT a a m Bool
forall a b. (a -> b) -> a -> b
$ a -> m Bool
f a
x
Bool -> ConduitT a a m () -> ConduitT a a m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
b (ConduitT a a m () -> ConduitT a a m ())
-> ConduitT a a m () -> ConduitT a a m ()
forall a b. (a -> b) -> a -> b
$ a -> ConduitT a a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
x
STREAMING(filterM, filterMC, filterMS, f)
filterME :: (Monad m, Seq.IsSequence seq) => (Element seq -> m Bool) -> ConduitT seq seq m ()
INLINE_RULE(filterME, f, CL.mapM (Seq.filterM f))
iterM :: Monad m => (a -> m ()) -> ConduitT a a m ()
INLINE_RULE(iterM, f, CL.iterM f)
scanlM, scanlMC :: Monad m => (a -> b -> m a) -> a -> ConduitT b a m ()
scanlMC :: forall (m :: * -> *) a b.
Monad m =>
(a -> b -> m a) -> a -> ConduitT b a m ()
scanlMC a -> b -> m a
f =
a -> ConduitT b a m ()
loop
where
loop :: a -> ConduitT b a m ()
loop a
seed =
ConduitT b a m (Maybe b)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT b a m (Maybe b)
-> (Maybe b -> ConduitT b a m ()) -> ConduitT b a m ()
forall a b.
ConduitT b a m a -> (a -> ConduitT b a m b) -> ConduitT b a m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT b a m ()
-> (b -> ConduitT b a m ()) -> Maybe b -> ConduitT b a m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (a -> ConduitT b a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
seed) b -> ConduitT b a m ()
go
where
go :: b -> ConduitT b a m ()
go b
b = do
a
seed' <- m a -> ConduitT b a m a
forall (m :: * -> *) a. Monad m => m a -> ConduitT b a m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> ConduitT b a m a) -> m a -> ConduitT b a m a
forall a b. (a -> b) -> a -> b
$ a -> b -> m a
f a
seed b
b
a
seed' a -> ConduitT b a m () -> ConduitT b a m ()
forall a b. a -> b -> b
`seq` a -> ConduitT b a m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
seed
a -> ConduitT b a m ()
loop a
seed'
STREAMING(scanlM, scanlMC, scanlMS, f x)
mapAccumWhileM, mapAccumWhileMC :: Monad m => (a -> s -> m (Either s (s, b))) -> s -> ConduitT a b m s
mapAccumWhileMC :: forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> m (Either s (s, b))) -> s -> ConduitT a b m s
mapAccumWhileMC a -> s -> m (Either s (s, b))
f =
s -> ConduitT a b m s
loop
where
loop :: s -> ConduitT a b m s
loop !s
s = ConduitT a b m (Maybe a)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT a b m (Maybe a)
-> (Maybe a -> ConduitT a b m s) -> ConduitT a b m s
forall a b.
ConduitT a b m a -> (a -> ConduitT a b m b) -> ConduitT a b m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT a b m s
-> (a -> ConduitT a b m s) -> Maybe a -> ConduitT a b m s
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (s -> ConduitT a b m s
forall a. a -> ConduitT a b m a
forall (m :: * -> *) a. Monad m => a -> m a
return s
s) a -> ConduitT a b m s
go
where
go :: a -> ConduitT a b m s
go a
a = m (Either s (s, b)) -> ConduitT a b m (Either s (s, b))
forall (m :: * -> *) a. Monad m => m a -> ConduitT a b m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (a -> s -> m (Either s (s, b))
f a
a s
s) ConduitT a b m (Either s (s, b))
-> (Either s (s, b) -> ConduitT a b m s) -> ConduitT a b m s
forall a b.
ConduitT a b m a -> (a -> ConduitT a b m b) -> ConduitT a b m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (s -> ConduitT a b m s)
-> ((s, b) -> ConduitT a b m s)
-> Either s (s, b)
-> ConduitT a b m s
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (s -> ConduitT a b m s
forall a. a -> ConduitT a b m a
forall (m :: * -> *) a. Monad m => a -> m a
return (s -> ConduitT a b m s) -> s -> ConduitT a b m s
forall a b. (a -> b) -> a -> b
$!) (\(s
s', b
b) -> b -> ConduitT a b m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
b ConduitT a b m () -> ConduitT a b m s -> ConduitT a b m s
forall a b.
ConduitT a b m a -> ConduitT a b m b -> ConduitT a b m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> s -> ConduitT a b m s
loop s
s')
{-# INLINE mapAccumWhileMC #-}
STREAMING(mapAccumWhileM, mapAccumWhileMC, mapAccumWhileMS, f s)
concatMapAccumM :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> ConduitT a b m ()
INLINE_RULE(concatMapAccumM, f x, CL.concatMapAccumM f x)
encodeUtf8 :: (Monad m, DTE.Utf8 text binary) => ConduitT text binary m ()
INLINE_RULE0(encodeUtf8, map DTE.encodeUtf8)
decodeUtf8 :: MonadThrow m => ConduitT ByteString Text m ()
decodeUtf8 :: forall (m :: * -> *). MonadThrow m => ConduitT ByteString Text m ()
decodeUtf8 =
(ByteString -> Decoding) -> ConduitT ByteString Text m ()
forall {m :: * -> *}.
MonadThrow m =>
(ByteString -> Decoding) -> ConduitT ByteString Text m ()
loop ByteString -> Decoding
TE.streamDecodeUtf8
where
loop :: (ByteString -> Decoding) -> ConduitT ByteString Text m ()
loop ByteString -> Decoding
parse =
ConduitT ByteString Text m (Maybe ByteString)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT ByteString Text m (Maybe ByteString)
-> (Maybe ByteString -> ConduitT ByteString Text m ())
-> ConduitT ByteString Text m ()
forall a b.
ConduitT ByteString Text m a
-> (a -> ConduitT ByteString Text m b)
-> ConduitT ByteString Text m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT ByteString Text m ()
-> (ByteString -> ConduitT ByteString Text m ())
-> Maybe ByteString
-> ConduitT ByteString Text m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ConduitT ByteString Text m ()
done ByteString -> ConduitT ByteString Text m ()
go
where
parse' :: ByteString -> Either UnicodeException Decoding
parse' = IO (Either UnicodeException Decoding)
-> Either UnicodeException Decoding
forall a. IO a -> a
unsafePerformIO (IO (Either UnicodeException Decoding)
-> Either UnicodeException Decoding)
-> (ByteString -> IO (Either UnicodeException Decoding))
-> ByteString
-> Either UnicodeException Decoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IO Decoding -> IO (Either UnicodeException Decoding)
forall e a. Exception e => IO a -> IO (Either e a)
try (IO Decoding -> IO (Either UnicodeException Decoding))
-> (ByteString -> IO Decoding)
-> ByteString
-> IO (Either UnicodeException Decoding)
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Decoding -> IO Decoding
forall a. a -> IO a
evaluate (Decoding -> IO Decoding)
-> (ByteString -> Decoding) -> ByteString -> IO Decoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> Decoding
parse
done :: ConduitT ByteString Text m ()
done =
case ByteString -> Either UnicodeException Decoding
parse' ByteString
forall a. Monoid a => a
mempty of
Left UnicodeException
e -> UnicodeException -> ConduitT ByteString Text m ()
forall e a.
(HasCallStack, Exception e) =>
e -> ConduitT ByteString Text m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (UnicodeException
e :: TEE.UnicodeException)
Right (TE.Some Text
t ByteString
bs ByteString -> Decoding
_) -> do
Bool
-> ConduitT ByteString Text m () -> ConduitT ByteString Text m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (Text -> ConduitT ByteString Text m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield Text
t)
Bool
-> ConduitT ByteString Text m () -> ConduitT ByteString Text m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) (Text -> ConduitT ByteString Text m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (Text -> ConduitT ByteString Text m ())
-> Text -> ConduitT ByteString Text m ()
forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.replicate (ByteString -> Int
S.length ByteString
bs) (Char -> Text
T.singleton Char
'\xFFFD'))
go :: ByteString -> ConduitT ByteString Text m ()
go ByteString
bs = do
case ByteString -> Either UnicodeException Decoding
parse' ByteString
bs of
Left UnicodeException
e -> do
ByteString -> ConduitT ByteString Text m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover ByteString
bs
UnicodeException -> ConduitT ByteString Text m ()
forall e a.
(HasCallStack, Exception e) =>
e -> ConduitT ByteString Text m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (UnicodeException
e :: TEE.UnicodeException)
Right (TE.Some Text
t ByteString
_ ByteString -> Decoding
next) -> do
Bool
-> ConduitT ByteString Text m () -> ConduitT ByteString Text m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (Text -> ConduitT ByteString Text m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield Text
t)
(ByteString -> Decoding) -> ConduitT ByteString Text m ()
loop ByteString -> Decoding
next
decodeUtf8Lenient :: Monad m => ConduitT ByteString Text m ()
decodeUtf8Lenient :: forall (m :: * -> *). Monad m => ConduitT ByteString Text m ()
decodeUtf8Lenient =
(ByteString -> Decoding) -> ConduitT ByteString Text m ()
forall {m :: * -> *}.
Monad m =>
(ByteString -> Decoding) -> ConduitT ByteString Text m ()
loop (OnDecodeError -> ByteString -> Decoding
TE.streamDecodeUtf8With OnDecodeError
TEE.lenientDecode)
where
loop :: (ByteString -> Decoding) -> ConduitT ByteString Text m ()
loop ByteString -> Decoding
parse =
ConduitT ByteString Text m (Maybe ByteString)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT ByteString Text m (Maybe ByteString)
-> (Maybe ByteString -> ConduitT ByteString Text m ())
-> ConduitT ByteString Text m ()
forall a b.
ConduitT ByteString Text m a
-> (a -> ConduitT ByteString Text m b)
-> ConduitT ByteString Text m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT ByteString Text m ()
-> (ByteString -> ConduitT ByteString Text m ())
-> Maybe ByteString
-> ConduitT ByteString Text m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ConduitT ByteString Text m ()
done ByteString -> ConduitT ByteString Text m ()
go
where
done :: ConduitT ByteString Text m ()
done = do
let TE.Some Text
t ByteString
bs ByteString -> Decoding
_ = ByteString -> Decoding
parse ByteString
forall a. Monoid a => a
mempty
Bool
-> ConduitT ByteString Text m () -> ConduitT ByteString Text m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (Text -> ConduitT ByteString Text m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield Text
t)
Bool
-> ConduitT ByteString Text m () -> ConduitT ByteString Text m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) (Text -> ConduitT ByteString Text m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (Text -> ConduitT ByteString Text m ())
-> Text -> ConduitT ByteString Text m ()
forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.replicate (ByteString -> Int
S.length ByteString
bs) (Char -> Text
T.singleton Char
'\xFFFD'))
go :: ByteString -> ConduitT ByteString Text m ()
go ByteString
bs = do
let TE.Some Text
t ByteString
_ ByteString -> Decoding
next = ByteString -> Decoding
parse ByteString
bs
Bool
-> ConduitT ByteString Text m () -> ConduitT ByteString Text m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (Text -> ConduitT ByteString Text m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield Text
t)
(ByteString -> Decoding) -> ConduitT ByteString Text m ()
loop ByteString -> Decoding
next
line :: (Monad m, Seq.IsSequence seq, Element seq ~ Char)
=> ConduitT seq o m r
-> ConduitT seq o m r
line :: forall (m :: * -> *) seq o r.
(Monad m, IsSequence seq, Element seq ~ Char) =>
ConduitT seq o m r -> ConduitT seq o m r
line = (Element seq -> Bool) -> ConduitT seq o m r -> ConduitT seq o m r
forall (m :: * -> *) seq o r.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq o m r -> ConduitT seq o m r
takeExactlyUntilE (Element seq -> Element seq -> Bool
forall a. Eq a => a -> a -> Bool
== Char
Element seq
'\n')
{-# INLINE line #-}
lineAscii :: (Monad m, Seq.IsSequence seq, Element seq ~ Word8)
=> ConduitT seq o m r
-> ConduitT seq o m r
lineAscii :: forall (m :: * -> *) seq o r.
(Monad m, IsSequence seq, Element seq ~ Word8) =>
ConduitT seq o m r -> ConduitT seq o m r
lineAscii = (Element seq -> Bool) -> ConduitT seq o m r -> ConduitT seq o m r
forall (m :: * -> *) seq o r.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq o m r -> ConduitT seq o m r
takeExactlyUntilE (Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
10)
{-# INLINE lineAscii #-}
takeExactlyUntilE :: (Monad m, Seq.IsSequence seq)
=> (Element seq -> Bool)
-> ConduitT seq o m r
-> ConduitT seq o m r
takeExactlyUntilE :: forall (m :: * -> *) seq o r.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq o m r -> ConduitT seq o m r
takeExactlyUntilE Element seq -> Bool
f ConduitT seq o m r
inner =
ConduitT seq seq m ()
loop ConduitT seq seq m () -> ConduitT seq o m r -> ConduitT seq o m r
forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| do
r
x <- ConduitT seq o m r
inner
ConduitT seq o m ()
forall (m :: * -> *) a o. Monad m => ConduitT a o m ()
sinkNull
r -> ConduitT seq o m r
forall a. a -> ConduitT seq o m a
forall (m :: * -> *) a. Monad m => a -> m a
return r
x
where
loop :: ConduitT seq seq m ()
loop = ConduitT seq seq m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT seq seq m (Maybe seq)
-> (Maybe seq -> ConduitT seq seq m ()) -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> (a -> ConduitT seq seq m b) -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Element (Maybe seq) -> ConduitT seq seq m ())
-> Maybe seq -> ConduitT seq seq m ()
forall mono (m :: * -> *).
(MonoFoldable mono, Applicative m) =>
(Element mono -> m ()) -> mono -> m ()
forall (m :: * -> *).
Applicative m =>
(Element (Maybe seq) -> m ()) -> Maybe seq -> m ()
omapM_ seq -> ConduitT seq seq m ()
Element (Maybe seq) -> ConduitT seq seq m ()
go
go :: seq -> ConduitT seq seq m ()
go seq
t =
if seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
y
then seq -> ConduitT seq seq m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
x ConduitT seq seq m ()
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> ConduitT seq seq m b -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT seq seq m ()
loop
else do
Bool -> ConduitT seq seq m () -> ConduitT seq seq m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
x) (ConduitT seq seq m () -> ConduitT seq seq m ())
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b. (a -> b) -> a -> b
$ seq -> ConduitT seq seq m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
x
let y' :: seq
y' = Index seq -> seq -> seq
forall seq. IsSequence seq => Index seq -> seq -> seq
Seq.drop Index seq
1 seq
y
Bool -> ConduitT seq seq m () -> ConduitT seq seq m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
y') (ConduitT seq seq m () -> ConduitT seq seq m ())
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b. (a -> b) -> a -> b
$ seq -> ConduitT seq seq m ()
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover seq
y'
where
(seq
x, seq
y) = (Element seq -> Bool) -> seq -> (seq, seq)
forall seq.
IsSequence seq =>
(Element seq -> Bool) -> seq -> (seq, seq)
Seq.break Element seq -> Bool
f seq
t
{-# INLINE takeExactlyUntilE #-}
unlines :: (Monad m, Seq.IsSequence seq, Element seq ~ Char) => ConduitT seq seq m ()
INLINE_RULE0(unlines, concatMap (:[Seq.singleton '\n']))
unlinesAscii :: (Monad m, Seq.IsSequence seq, Element seq ~ Word8) => ConduitT seq seq m ()
INLINE_RULE0(unlinesAscii, concatMap (:[Seq.singleton 10]))
splitOnUnboundedE, splitOnUnboundedEC :: (Monad m, Seq.IsSequence seq) => (Element seq -> Bool) -> ConduitT seq seq m ()
splitOnUnboundedEC :: forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq seq m ()
splitOnUnboundedEC Element seq -> Bool
f =
ConduitT seq seq m ()
start
where
start :: ConduitT seq seq m ()
start = ConduitT seq seq m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await ConduitT seq seq m (Maybe seq)
-> (Maybe seq -> ConduitT seq seq m ()) -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> (a -> ConduitT seq seq m b) -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ConduitT seq seq m ()
-> (seq -> ConduitT seq seq m ())
-> Maybe seq
-> ConduitT seq seq m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> ConduitT seq seq m ()
forall a. a -> ConduitT seq seq m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (([seq] -> [seq]) -> seq -> ConduitT seq seq m ()
loop [seq] -> [seq]
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id)
loop :: ([seq] -> [seq]) -> seq -> ConduitT seq seq m ()
loop [seq] -> [seq]
bldr seq
t =
if seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
y
then do
Maybe seq
mt <- ConduitT seq seq m (Maybe seq)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
case Maybe seq
mt of
Maybe seq
Nothing -> let finalChunk :: seq
finalChunk = [seq] -> seq
forall a. Monoid a => [a] -> a
mconcat ([seq] -> seq) -> [seq] -> seq
forall a b. (a -> b) -> a -> b
$ [seq] -> [seq]
bldr [seq
t]
in Bool -> ConduitT seq seq m () -> ConduitT seq seq m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (seq -> Bool
forall mono. MonoFoldable mono => mono -> Bool
onull seq
finalChunk) (ConduitT seq seq m () -> ConduitT seq seq m ())
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b. (a -> b) -> a -> b
$ seq -> ConduitT seq seq m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
finalChunk
Just seq
t' -> ([seq] -> [seq]) -> seq -> ConduitT seq seq m ()
loop ([seq] -> [seq]
bldr ([seq] -> [seq]) -> ([seq] -> [seq]) -> [seq] -> [seq]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (seq
tseq -> [seq] -> [seq]
forall a. a -> [a] -> [a]
:)) seq
t'
else seq -> ConduitT seq seq m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield ([seq] -> seq
forall a. Monoid a => [a] -> a
mconcat ([seq] -> seq) -> [seq] -> seq
forall a b. (a -> b) -> a -> b
$ [seq] -> [seq]
bldr [seq
x]) ConduitT seq seq m ()
-> ConduitT seq seq m () -> ConduitT seq seq m ()
forall a b.
ConduitT seq seq m a
-> ConduitT seq seq m b -> ConduitT seq seq m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ([seq] -> [seq]) -> seq -> ConduitT seq seq m ()
loop [seq] -> [seq]
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id (Index seq -> seq -> seq
forall seq. IsSequence seq => Index seq -> seq -> seq
Seq.drop Index seq
1 seq
y)
where
(seq
x, seq
y) = (Element seq -> Bool) -> seq -> (seq, seq)
forall seq.
IsSequence seq =>
(Element seq -> Bool) -> seq -> (seq, seq)
Seq.break Element seq -> Bool
f seq
t
STREAMING(splitOnUnboundedE, splitOnUnboundedEC, splitOnUnboundedES, f)
linesUnbounded :: (Monad m, Seq.IsSequence seq, Element seq ~ Char)
=> ConduitT seq seq m ()
INLINE_RULE0(linesUnbounded, splitOnUnboundedE (== '\n'))
linesUnboundedAscii :: (Monad m, Seq.IsSequence seq, Element seq ~ Word8)
=> ConduitT seq seq m ()
INLINE_RULE0(linesUnboundedAscii, splitOnUnboundedE (== 10))
builderToByteString :: PrimMonad m => ConduitT Builder S.ByteString m ()
builderToByteString :: forall (m :: * -> *).
PrimMonad m =>
ConduitT Builder ByteString m ()
builderToByteString = BufferAllocStrategy -> ConduitT Builder ByteString m ()
forall (m :: * -> *).
PrimMonad m =>
BufferAllocStrategy -> ConduitT Builder ByteString m ()
builderToByteStringWith BufferAllocStrategy
defaultStrategy
{-# INLINE builderToByteString #-}
builderToByteStringFlush :: PrimMonad m
=> ConduitT (Flush Builder) (Flush S.ByteString) m ()
builderToByteStringFlush :: forall (m :: * -> *).
PrimMonad m =>
ConduitT (Flush Builder) (Flush ByteString) m ()
builderToByteStringFlush = BufferAllocStrategy
-> ConduitT (Flush Builder) (Flush ByteString) m ()
forall (m :: * -> *).
PrimMonad m =>
BufferAllocStrategy
-> ConduitT (Flush Builder) (Flush ByteString) m ()
builderToByteStringWithFlush BufferAllocStrategy
defaultStrategy
{-# INLINE builderToByteStringFlush #-}
unsafeBuilderToByteString :: PrimMonad m
=> ConduitT Builder S.ByteString m ()
unsafeBuilderToByteString :: forall (m :: * -> *).
PrimMonad m =>
ConduitT Builder ByteString m ()
unsafeBuilderToByteString =
BufferAllocStrategy -> ConduitT Builder ByteString m ()
forall (m :: * -> *).
PrimMonad m =>
BufferAllocStrategy -> ConduitT Builder ByteString m ()
builderToByteStringWith (IO Buffer -> BufferAllocStrategy
reuseBufferStrategy (Int -> IO Buffer
allocBuffer Int
defaultChunkSize))
{-# INLINE unsafeBuilderToByteString #-}
builderToByteStringWith :: PrimMonad m
=> BufferAllocStrategy
-> ConduitT Builder S.ByteString m ()
builderToByteStringWith :: forall (m :: * -> *).
PrimMonad m =>
BufferAllocStrategy -> ConduitT Builder ByteString m ()
builderToByteStringWith =
ConduitT Builder ByteString m (Maybe (Flush Builder))
-> (Flush ByteString -> ConduitT Builder ByteString m ())
-> BufferAllocStrategy
-> ConduitT Builder ByteString m ()
forall (m :: * -> *).
PrimMonad m =>
m (Maybe (Flush Builder))
-> (Flush ByteString -> m ()) -> BufferAllocStrategy -> m ()
bbhelper ((Maybe Builder -> Maybe (Flush Builder))
-> ConduitT Builder ByteString m (Maybe Builder)
-> ConduitT Builder ByteString m (Maybe (Flush Builder))
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((Builder -> Flush Builder)
-> Maybe Builder -> Maybe (Flush Builder)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Builder -> Flush Builder
forall a. a -> Flush a
Chunk) ConduitT Builder ByteString m (Maybe Builder)
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await) Flush ByteString -> ConduitT Builder ByteString m ()
forall {m :: * -> *} {o} {i}.
Monad m =>
Flush o -> ConduitT i o m ()
yield'
where
yield' :: Flush o -> ConduitT i o m ()
yield' Flush o
Flush = () -> ConduitT i o m ()
forall a. a -> ConduitT i o m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
yield' (Chunk o
bs) = o -> ConduitT i o m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield o
bs
{-# INLINE builderToByteStringWith #-}
builderToByteStringWithFlush
:: PrimMonad m
=> BufferAllocStrategy
-> ConduitT (Flush Builder) (Flush S.ByteString) m ()
builderToByteStringWithFlush :: forall (m :: * -> *).
PrimMonad m =>
BufferAllocStrategy
-> ConduitT (Flush Builder) (Flush ByteString) m ()
builderToByteStringWithFlush = ConduitT
(Flush Builder) (Flush ByteString) m (Maybe (Flush Builder))
-> (Flush ByteString
-> ConduitT (Flush Builder) (Flush ByteString) m ())
-> BufferAllocStrategy
-> ConduitT (Flush Builder) (Flush ByteString) m ()
forall (m :: * -> *).
PrimMonad m =>
m (Maybe (Flush Builder))
-> (Flush ByteString -> m ()) -> BufferAllocStrategy -> m ()
bbhelper ConduitT
(Flush Builder) (Flush ByteString) m (Maybe (Flush Builder))
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await Flush ByteString
-> ConduitT (Flush Builder) (Flush ByteString) m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE builderToByteStringWithFlush #-}
bbhelper
:: PrimMonad m
=> m (Maybe (Flush Builder))
-> (Flush S.ByteString -> m ())
-> BufferAllocStrategy
-> m ()
bbhelper :: forall (m :: * -> *).
PrimMonad m =>
m (Maybe (Flush Builder))
-> (Flush ByteString -> m ()) -> BufferAllocStrategy -> m ()
bbhelper m (Maybe (Flush Builder))
await' Flush ByteString -> m ()
yield' BufferAllocStrategy
strat = do
(BuilderRecv
recv, BuilderFinish
finish) <- IO (BuilderRecv, BuilderFinish) -> m (BuilderRecv, BuilderFinish)
forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim (IO (BuilderRecv, BuilderFinish) -> m (BuilderRecv, BuilderFinish))
-> IO (BuilderRecv, BuilderFinish)
-> m (BuilderRecv, BuilderFinish)
forall a b. (a -> b) -> a -> b
$ BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish)
newByteStringBuilderRecv BufferAllocStrategy
strat
let loop :: m ()
loop = m (Maybe (Flush Builder))
await' m (Maybe (Flush Builder))
-> (Maybe (Flush Builder) -> m ()) -> m ()
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m () -> (Flush Builder -> m ()) -> Maybe (Flush Builder) -> m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe m ()
finish' Flush Builder -> m ()
cont
finish' :: m ()
finish' = do
Maybe ByteString
mbs <- BuilderFinish -> m (Maybe ByteString)
forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim BuilderFinish
finish
m () -> (ByteString -> m ()) -> Maybe ByteString -> m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Flush ByteString -> m ()
yield' (Flush ByteString -> m ())
-> (ByteString -> Flush ByteString) -> ByteString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> Flush ByteString
forall a. a -> Flush a
Chunk) Maybe ByteString
mbs
cont :: Flush Builder -> m ()
cont Flush Builder
fbuilder = do
let builder :: Builder
builder =
case Flush Builder
fbuilder of
Flush Builder
Flush -> Builder
BB.flush
Chunk Builder
b -> Builder
b
IO ByteString
popper <- IO (IO ByteString) -> m (IO ByteString)
forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim (IO (IO ByteString) -> m (IO ByteString))
-> IO (IO ByteString) -> m (IO ByteString)
forall a b. (a -> b) -> a -> b
$ BuilderRecv
recv Builder
builder
let cont' :: m ()
cont' = do
ByteString
bs <- IO ByteString -> m ByteString
forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim IO ByteString
popper
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Flush ByteString -> m ()
yield' (ByteString -> Flush ByteString
forall a. a -> Flush a
Chunk ByteString
bs)
m ()
cont'
m ()
cont'
case Flush Builder
fbuilder of
Flush Builder
Flush -> Flush ByteString -> m ()
yield' Flush ByteString
forall a. Flush a
Flush
Chunk Builder
_ -> () -> m ()
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
m ()
loop
m ()
loop
{-# INLINE bbhelper #-}
type BuilderPopper = IO S.ByteString
type BuilderRecv = Builder -> IO BuilderPopper
type BuilderFinish = IO (Maybe S.ByteString)
newByteStringBuilderRecv :: BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish)
newByteStringBuilderRecv :: BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish)
newByteStringBuilderRecv (IO Buffer
ioBufInit, Int -> Buffer -> IO (IO Buffer)
nextBuf) = do
IORef (IO Buffer)
refBuf <- IO Buffer -> IO (IORef (IO Buffer))
forall a. a -> IO (IORef a)
newIORef IO Buffer
ioBufInit
(BuilderRecv, BuilderFinish) -> IO (BuilderRecv, BuilderFinish)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IORef (IO Buffer) -> BuilderRecv
push IORef (IO Buffer)
refBuf, IORef (IO Buffer) -> BuilderFinish
finish IORef (IO Buffer)
refBuf)
where
finish :: IORef (IO Buffer) -> BuilderFinish
finish IORef (IO Buffer)
refBuf = do
IO Buffer
ioBuf <- IORef (IO Buffer) -> IO (IO Buffer)
forall a. IORef a -> IO a
readIORef IORef (IO Buffer)
refBuf
Buffer
buf <- IO Buffer
ioBuf
Maybe ByteString -> BuilderFinish
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe ByteString -> BuilderFinish)
-> Maybe ByteString -> BuilderFinish
forall a b. (a -> b) -> a -> b
$ Buffer -> Maybe ByteString
unsafeFreezeNonEmptyBuffer Buffer
buf
push :: IORef (IO Buffer) -> BuilderRecv
push IORef (IO Buffer)
refBuf Builder
builder = do
IORef (Either BufferWriter (IO ByteString))
refWri <- Either BufferWriter (IO ByteString)
-> IO (IORef (Either BufferWriter (IO ByteString)))
forall a. a -> IO (IORef a)
newIORef (Either BufferWriter (IO ByteString)
-> IO (IORef (Either BufferWriter (IO ByteString))))
-> Either BufferWriter (IO ByteString)
-> IO (IORef (Either BufferWriter (IO ByteString)))
forall a b. (a -> b) -> a -> b
$ BufferWriter -> Either BufferWriter (IO ByteString)
forall a b. a -> Either a b
Left (BufferWriter -> Either BufferWriter (IO ByteString))
-> BufferWriter -> Either BufferWriter (IO ByteString)
forall a b. (a -> b) -> a -> b
$ Builder -> BufferWriter
BB.runBuilder Builder
builder
IO ByteString -> IO (IO ByteString)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IO ByteString -> IO (IO ByteString))
-> IO ByteString -> IO (IO ByteString)
forall a b. (a -> b) -> a -> b
$ IORef (IO Buffer)
-> IORef (Either BufferWriter (IO ByteString)) -> IO ByteString
popper IORef (IO Buffer)
refBuf IORef (Either BufferWriter (IO ByteString))
refWri
popper :: IORef (IO Buffer)
-> IORef (Either BufferWriter (IO ByteString)) -> IO ByteString
popper IORef (IO Buffer)
refBuf IORef (Either BufferWriter (IO ByteString))
refWri = do
IO Buffer
ioBuf <- IORef (IO Buffer) -> IO (IO Buffer)
forall a. IORef a -> IO a
readIORef IORef (IO Buffer)
refBuf
Either BufferWriter (IO ByteString)
ebWri <- IORef (Either BufferWriter (IO ByteString))
-> IO (Either BufferWriter (IO ByteString))
forall a. IORef a -> IO a
readIORef IORef (Either BufferWriter (IO ByteString))
refWri
case Either BufferWriter (IO ByteString)
ebWri of
Left BufferWriter
bWri -> do
!buf :: Buffer
buf@(Buffer ForeignPtr Word8
_ Ptr Word8
_ Ptr Word8
op Ptr Word8
ope) <- IO Buffer
ioBuf
(Int
bytes, Next
next) <- BufferWriter
bWri Ptr Word8
op (Ptr Word8
ope Ptr Word8 -> Ptr Word8 -> Int
forall a b. Ptr a -> Ptr b -> Int
`minusPtr` Ptr Word8
op)
let op' :: Ptr Word8
op' = Ptr Word8
op Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
bytes
case Next
next of
Next
BB.Done -> do
IORef (IO Buffer) -> IO Buffer -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef (IO Buffer)
refBuf (IO Buffer -> IO ()) -> IO Buffer -> IO ()
forall a b. (a -> b) -> a -> b
$ Buffer -> IO Buffer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Buffer -> IO Buffer) -> Buffer -> IO Buffer
forall a b. (a -> b) -> a -> b
$ Buffer -> Ptr Word8 -> Buffer
updateEndOfSlice Buffer
buf Ptr Word8
op'
ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
S.empty
BB.More Int
minSize BufferWriter
bWri' -> do
let buf' :: Buffer
buf' = Buffer -> Ptr Word8 -> Buffer
updateEndOfSlice Buffer
buf Ptr Word8
op'
{-# INLINE cont #-}
cont :: Maybe ByteString -> IO ByteString
cont Maybe ByteString
mbs = do
IO Buffer
ioBuf' <- Int -> Buffer -> IO (IO Buffer)
nextBuf Int
minSize Buffer
buf'
IORef (IO Buffer) -> IO Buffer -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef (IO Buffer)
refBuf IO Buffer
ioBuf'
IORef (Either BufferWriter (IO ByteString))
-> Either BufferWriter (IO ByteString) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef (Either BufferWriter (IO ByteString))
refWri (Either BufferWriter (IO ByteString) -> IO ())
-> Either BufferWriter (IO ByteString) -> IO ()
forall a b. (a -> b) -> a -> b
$ BufferWriter -> Either BufferWriter (IO ByteString)
forall a b. a -> Either a b
Left BufferWriter
bWri'
case Maybe ByteString
mbs of
Just ByteString
bs | Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ByteString -> Bool
S.null ByteString
bs -> ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
bs
Maybe ByteString
_ -> IORef (IO Buffer)
-> IORef (Either BufferWriter (IO ByteString)) -> IO ByteString
popper IORef (IO Buffer)
refBuf IORef (Either BufferWriter (IO ByteString))
refWri
Maybe ByteString -> IO ByteString
cont (Maybe ByteString -> IO ByteString)
-> Maybe ByteString -> IO ByteString
forall a b. (a -> b) -> a -> b
$ Buffer -> Maybe ByteString
unsafeFreezeNonEmptyBuffer Buffer
buf'
BB.Chunk ByteString
bs BufferWriter
bWri' -> do
let buf' :: Buffer
buf' = Buffer -> Ptr Word8 -> Buffer
updateEndOfSlice Buffer
buf Ptr Word8
op'
let yieldBS :: IO ByteString
yieldBS = do
Int -> Buffer -> IO (IO Buffer)
nextBuf Int
1 Buffer
buf' IO (IO Buffer) -> (IO Buffer -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IORef (IO Buffer) -> IO Buffer -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef (IO Buffer)
refBuf
IORef (Either BufferWriter (IO ByteString))
-> Either BufferWriter (IO ByteString) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef (Either BufferWriter (IO ByteString))
refWri (Either BufferWriter (IO ByteString) -> IO ())
-> Either BufferWriter (IO ByteString) -> IO ()
forall a b. (a -> b) -> a -> b
$ BufferWriter -> Either BufferWriter (IO ByteString)
forall a b. a -> Either a b
Left BufferWriter
bWri'
if ByteString -> Bool
S.null ByteString
bs
then IORef (IO Buffer)
-> IORef (Either BufferWriter (IO ByteString)) -> IO ByteString
popper IORef (IO Buffer)
refBuf IORef (Either BufferWriter (IO ByteString))
refWri
else ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
bs
case Buffer -> Maybe ByteString
unsafeFreezeNonEmptyBuffer Buffer
buf' of
Maybe ByteString
Nothing -> IO ByteString
yieldBS
Just ByteString
bs' -> do
IORef (Either BufferWriter (IO ByteString))
-> Either BufferWriter (IO ByteString) -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef (Either BufferWriter (IO ByteString))
refWri (Either BufferWriter (IO ByteString) -> IO ())
-> Either BufferWriter (IO ByteString) -> IO ()
forall a b. (a -> b) -> a -> b
$ IO ByteString -> Either BufferWriter (IO ByteString)
forall a b. b -> Either a b
Right IO ByteString
yieldBS
ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
bs'
Right IO ByteString
action -> IO ByteString
action
data Buffer = Buffer {-# UNPACK #-} !(ForeignPtr Word8)
{-# UNPACK #-} !(Ptr Word8)
{-# UNPACK #-} !(Ptr Word8)
{-# UNPACK #-} !(Ptr Word8)
{-# INLINE unsafeFreezeBuffer #-}
unsafeFreezeBuffer :: Buffer -> S.ByteString
unsafeFreezeBuffer :: Buffer -> ByteString
unsafeFreezeBuffer (Buffer ForeignPtr Word8
fpbuf Ptr Word8
p0 Ptr Word8
op Ptr Word8
_) =
ForeignPtr Word8 -> Int -> Int -> ByteString
PS ForeignPtr Word8
fpbuf (Ptr Word8
p0 Ptr Word8 -> Ptr Word8 -> Int
forall a b. Ptr a -> Ptr b -> Int
`minusPtr` ForeignPtr Word8 -> Ptr Word8
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fpbuf) (Ptr Word8
op Ptr Word8 -> Ptr Word8 -> Int
forall a b. Ptr a -> Ptr b -> Int
`minusPtr` Ptr Word8
p0)
{-# INLINE unsafeFreezeNonEmptyBuffer #-}
unsafeFreezeNonEmptyBuffer :: Buffer -> Maybe S.ByteString
unsafeFreezeNonEmptyBuffer :: Buffer -> Maybe ByteString
unsafeFreezeNonEmptyBuffer Buffer
buf
| Buffer -> Int
sliceSize Buffer
buf Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = Maybe ByteString
forall a. Maybe a
Nothing
| Bool
otherwise = ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Buffer -> ByteString
unsafeFreezeBuffer Buffer
buf
{-# INLINE updateEndOfSlice #-}
updateEndOfSlice :: Buffer
-> Ptr Word8
-> Buffer
updateEndOfSlice :: Buffer -> Ptr Word8 -> Buffer
updateEndOfSlice (Buffer ForeignPtr Word8
fpbuf Ptr Word8
p0 Ptr Word8
_ Ptr Word8
ope) Ptr Word8
op' = ForeignPtr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Buffer
Buffer ForeignPtr Word8
fpbuf Ptr Word8
p0 Ptr Word8
op' Ptr Word8
ope
sliceSize :: Buffer -> Int
sliceSize :: Buffer -> Int
sliceSize (Buffer ForeignPtr Word8
_ Ptr Word8
p0 Ptr Word8
op Ptr Word8
_) = Ptr Word8
op Ptr Word8 -> Ptr Word8 -> Int
forall a b. Ptr a -> Ptr b -> Int
`minusPtr` Ptr Word8
p0
type BufferAllocStrategy = (IO Buffer, Int -> Buffer -> IO (IO Buffer))
defaultStrategy :: BufferAllocStrategy
defaultStrategy :: BufferAllocStrategy
defaultStrategy = Int -> BufferAllocStrategy
allNewBuffersStrategy Int
defaultChunkSize
allNewBuffersStrategy :: Int
-> BufferAllocStrategy
Int
bufSize =
( Int -> IO Buffer
allocBuffer Int
bufSize
, \Int
reqSize Buffer
_ -> IO Buffer -> IO (IO Buffer)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> IO Buffer
allocBuffer (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
reqSize Int
bufSize)) )
reuseBufferStrategy :: IO Buffer
-> BufferAllocStrategy
reuseBufferStrategy :: IO Buffer -> BufferAllocStrategy
reuseBufferStrategy IO Buffer
buf0 =
(IO Buffer
buf0, Int -> Buffer -> IO (IO Buffer)
forall {m :: * -> *}. Monad m => Int -> Buffer -> m (IO Buffer)
tryReuseBuffer)
where
tryReuseBuffer :: Int -> Buffer -> m (IO Buffer)
tryReuseBuffer Int
reqSize Buffer
buf
| Buffer -> Int
bufferSize Buffer
buf Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
reqSize = IO Buffer -> m (IO Buffer)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IO Buffer -> m (IO Buffer)) -> IO Buffer -> m (IO Buffer)
forall a b. (a -> b) -> a -> b
$ Buffer -> IO Buffer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Buffer -> Buffer
reuseBuffer Buffer
buf)
| Bool
otherwise = IO Buffer -> m (IO Buffer)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (IO Buffer -> m (IO Buffer)) -> IO Buffer -> m (IO Buffer)
forall a b. (a -> b) -> a -> b
$ Int -> IO Buffer
allocBuffer Int
reqSize
bufferSize :: Buffer -> Int
bufferSize :: Buffer -> Int
bufferSize (Buffer ForeignPtr Word8
fpbuf Ptr Word8
_ Ptr Word8
_ Ptr Word8
ope) =
Ptr Word8
ope Ptr Word8 -> Ptr Word8 -> Int
forall a b. Ptr a -> Ptr b -> Int
`minusPtr` ForeignPtr Word8 -> Ptr Word8
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fpbuf
{-# INLINE allocBuffer #-}
allocBuffer :: Int -> IO Buffer
allocBuffer :: Int -> IO Buffer
allocBuffer Int
size = do
ForeignPtr Word8
fpbuf <- Int -> IO (ForeignPtr Word8)
forall a. Int -> IO (ForeignPtr a)
mallocByteString Int
size
let !pbuf :: Ptr Word8
pbuf = ForeignPtr Word8 -> Ptr Word8
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fpbuf
Buffer -> IO Buffer
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Buffer -> IO Buffer) -> Buffer -> IO Buffer
forall a b. (a -> b) -> a -> b
$! ForeignPtr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Buffer
Buffer ForeignPtr Word8
fpbuf Ptr Word8
pbuf Ptr Word8
pbuf (Ptr Word8
pbuf Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
size)
{-# INLINE reuseBuffer #-}
reuseBuffer :: Buffer -> Buffer
reuseBuffer :: Buffer -> Buffer
reuseBuffer (Buffer ForeignPtr Word8
fpbuf Ptr Word8
_ Ptr Word8
_ Ptr Word8
ope) = ForeignPtr Word8 -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Buffer
Buffer ForeignPtr Word8
fpbuf Ptr Word8
p0 Ptr Word8
p0 Ptr Word8
ope
where
p0 :: Ptr Word8
p0 = ForeignPtr Word8 -> Ptr Word8
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fpbuf
vectorBuilder :: (PrimMonad m, PrimMonad n, V.Vector v e, PrimState m ~ PrimState n)
=> Int
-> ((e -> n ()) -> ConduitT i Void m r)
-> ConduitT i (v e) m r
vectorBuilder :: forall (m :: * -> *) (n :: * -> *) (v :: * -> *) e i r.
(PrimMonad m, PrimMonad n, Vector v e,
PrimState m ~ PrimState n) =>
Int -> ((e -> n ()) -> ConduitT i Void m r) -> ConduitT i (v e) m r
vectorBuilder Int
size (e -> n ()) -> ConduitT i Void m r
inner = do
MutVar (PrimState n) (S (PrimState n) v e)
ref <- do
Mutable v (PrimState n) e
mv <- Int
-> ConduitT
i (v e) m (Mutable v (PrimState (ConduitT i (v e) m)) e)
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VM.new Int
size
S (PrimState n) v e
-> ConduitT i (v e) m (MutVar (PrimState n) (S (PrimState n) v e))
S (PrimState n) v e
-> ConduitT
i
(v e)
m
(MutVar (PrimState (ConduitT i (v e) m)) (S (PrimState n) v e))
forall (m :: * -> *) a.
PrimMonad m =>
a -> m (MutVar (PrimState m) a)
newMutVar (S (PrimState n) v e
-> ConduitT i (v e) m (MutVar (PrimState n) (S (PrimState n) v e)))
-> S (PrimState n) v e
-> ConduitT i (v e) m (MutVar (PrimState n) (S (PrimState n) v e))
forall a b. (a -> b) -> a -> b
$! Int
-> Mutable v (PrimState n) e
-> ([v e] -> [v e])
-> S (PrimState n) v e
forall s (v :: * -> *) e.
Int -> Mutable v s e -> ([v e] -> [v e]) -> S s v e
S Int
0 Mutable v (PrimState n) e
mv [v e] -> [v e]
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
r
res <- ConduitT i (v e) m ()
-> ConduitT i Void m r -> ConduitT i (v e) m r
forall (m :: * -> *) i o r.
Monad m =>
ConduitT i o m () -> ConduitT i Void m r -> ConduitT i o m r
onAwait (MutVar (PrimState m) (S (PrimState m) v e) -> ConduitT i (v e) m ()
forall (m :: * -> *) (v :: * -> *) e i.
PrimMonad m =>
MutVar (PrimState m) (S (PrimState m) v e) -> ConduitT i (v e) m ()
yieldS MutVar (PrimState m) (S (PrimState m) v e)
MutVar (PrimState n) (S (PrimState n) v e)
ref) ((e -> n ()) -> ConduitT i Void m r
inner (MutVar (PrimState n) (S (PrimState n) v e) -> e -> n ()
forall (m :: * -> *) (v :: * -> *) e.
(PrimMonad m, Vector v e) =>
MutVar (PrimState m) (S (PrimState m) v e) -> e -> m ()
addE MutVar (PrimState n) (S (PrimState n) v e)
ref))
[v e]
vs <- do
S Int
idx Mutable v (PrimState n) e
mv [v e] -> [v e]
front <- MutVar (PrimState (ConduitT i (v e) m)) (S (PrimState n) v e)
-> ConduitT i (v e) m (S (PrimState n) v e)
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar (PrimState n) (S (PrimState n) v e)
MutVar (PrimState (ConduitT i (v e) m)) (S (PrimState n) v e)
ref
[v e]
end <-
if Int
idx Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then [v e] -> ConduitT i (v e) m [v e]
forall a. a -> ConduitT i (v e) m a
forall (m :: * -> *) a. Monad m => a -> m a
return []
else do
v e
v <- Mutable v (PrimState (ConduitT i (v e) m)) e
-> ConduitT i (v e) m (v e)
forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState n) e
Mutable v (PrimState (ConduitT i (v e) m)) e
mv
[v e] -> ConduitT i (v e) m [v e]
forall a. a -> ConduitT i (v e) m a
forall (m :: * -> *) a. Monad m => a -> m a
return [Int -> v e -> v e
forall (v :: * -> *) a. Vector v a => Int -> v a -> v a
V.unsafeTake Int
idx v e
v]
[v e] -> ConduitT i (v e) m [v e]
forall a. a -> ConduitT i (v e) m a
forall (m :: * -> *) a. Monad m => a -> m a
return ([v e] -> ConduitT i (v e) m [v e])
-> [v e] -> ConduitT i (v e) m [v e]
forall a b. (a -> b) -> a -> b
$ [v e] -> [v e]
front [v e]
end
(v e -> ConduitT i (v e) m ()) -> [v e] -> ConduitT i (v e) m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
Prelude.mapM_ v e -> ConduitT i (v e) m ()
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield [v e]
vs
r -> ConduitT i (v e) m r
forall a. a -> ConduitT i (v e) m a
forall (m :: * -> *) a. Monad m => a -> m a
return r
res
{-# INLINE vectorBuilder #-}
data S s v e = S
{-# UNPACK #-} !Int
!(V.Mutable v s e)
([v e] -> [v e])
onAwait :: Monad m
=> ConduitT i o m ()
-> ConduitT i Void m r
-> ConduitT i o m r
onAwait :: forall (m :: * -> *) i o r.
Monad m =>
ConduitT i o m () -> ConduitT i Void m r -> ConduitT i o m r
onAwait (ConduitT forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b
callback) (ConduitT forall b. (r -> Pipe i i Void () m b) -> Pipe i i Void () m b
sink0) = (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 Void () m r -> Pipe i i o () m b
go (Done r
r) = r -> Pipe i i o () m b
rest r
r
go (HaveOutput Pipe i i Void () m r
_ Void
o) = Void -> Pipe i i o () m b
forall a. Void -> a
absurd Void
o
go (NeedInput i -> Pipe i i Void () m r
f () -> Pipe i i Void () m r
g) = (() -> Pipe i i o () m b) -> Pipe i i o () m b
forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b
callback ((() -> 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
$ \() -> (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 Void () m r -> Pipe i i o () m b
go (Pipe i i Void () m r -> Pipe i i o () m b)
-> (i -> Pipe i i Void () m r) -> i -> Pipe i i o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. i -> Pipe i i Void () m r
f) (Pipe i i Void () m r -> Pipe i i o () m b
go (Pipe i i Void () m r -> Pipe i i o () m b)
-> (() -> Pipe i i Void () m r) -> () -> Pipe i i o () m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. () -> Pipe i i Void () m r
g)
go (PipeM m (Pipe i i Void () 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 ((Pipe i i Void () m r -> Pipe i i o () m b)
-> m (Pipe i i Void () 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 Void () m r -> Pipe i i o () m b
go m (Pipe i i Void () m r)
mp)
go (Leftover Pipe i i Void () m r
f 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 Void () m r -> Pipe i i o () m b
go Pipe i i Void () m r
f) i
i
in Pipe i i Void () m r -> Pipe i i o () m b
go ((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)
{-# INLINE onAwait #-}
yieldS :: PrimMonad m
=> MutVar (PrimState m) (S (PrimState m) v e)
-> ConduitT i (v e) m ()
yieldS :: forall (m :: * -> *) (v :: * -> *) e i.
PrimMonad m =>
MutVar (PrimState m) (S (PrimState m) v e) -> ConduitT i (v e) m ()
yieldS MutVar (PrimState m) (S (PrimState m) v e)
ref = do