{-# 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 = forall mono m.
(MonoFoldable mono, Monoid m) =>
(Element mono -> m) -> mono -> m
ofoldMap 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 = forall (f :: * -> *) a b. Applicative f => f a -> f b
forever forall a b. (a -> b) -> a -> b
$ forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m a
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield
{-# INLINE 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 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m a
m
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (a -> Bool
f a
x) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> 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 =
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
forall {m :: * -> *} {i}.
MonadIO m =>
ReadHandle -> ConduitT i ByteString m ()
loop
where
loop :: ReadHandle -> ConduitT i ByteString m ()
loop ReadHandle
h = do
ByteString
bs <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ ReadHandle -> IO ByteString
FR.readChunk ReadHandle
h
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) forall a b. (a -> b) -> a -> b
$ do
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 <- 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 forall (m :: * -> *) a. Monad m => a -> m a
return ()
else forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield ByteString
bs 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 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. Int -> IO (ForeignPtr a)
mallocPlainForeignPtrBytes Int
defaultChunkSize
let ptr :: Ptr Word8
ptr = forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fptr
loop :: ConduitT i ByteString m ()
loop = do
Int
count <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a. Handle -> Ptr a -> Int -> IO Int
IO.hGetBuf Handle
handle Ptr Word8
ptr Int
defaultChunkSize
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
count forall a. Ord a => a -> a -> Bool
> Int
0) forall a b. (a -> b) -> a -> b
$ do
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
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ 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 = 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 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 = 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 = 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 =
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
forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle Handle
h
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO 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 (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run -> 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 <- forall a. m a -> IO a
run forall a b. (a -> b) -> a -> b
$ ConduitM ByteString o n () -> m a
inner forall a b. (a -> b) -> a -> b
$ 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
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 forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`Control.Exception.catch` \IOError
e ->
if IOError -> Bool
isDoesNotExistError IOError
e
then forall (m :: * -> *) a. Monad m => a -> m a
return ()
else 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)) <- 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 forall a b. IO a -> IO b -> IO a
`finally` (FilePath -> IO ()
removeFile FilePath
fp forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`Control.Exception.catch` \IOError
e ->
if IOError -> Bool
isDoesNotExistError IOError
e
then forall (m :: * -> *) a. Monad m => a -> m a
return ()
else forall e a. Exception e => e -> IO a
throwIO IOError
e))
forall (m :: * -> *) o.
MonadIO m =>
Handle -> ConduitT ByteString o m ()
sinkHandle Handle
h
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Handle -> IO ()
IO.hClose Handle
h
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 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO FilePath
getTemporaryDirectory
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 = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO 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 = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO 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 =
forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever forall a b. (a -> b) -> a -> b
$ \Flush ByteString
mbs -> forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO 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 = 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 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 (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
IO.withBinaryFile FilePath
fp IOMode
IO.ReadMode forall a b. (a -> b) -> a -> b
$
forall a. m a -> IO a
run 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 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. 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 (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
IO.withBinaryFile FilePath
fp IOMode
IO.WriteMode forall a b. (a -> b) -> a -> b
$
forall a. m a -> IO a
run 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 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. 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 (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO forall a b. (a -> b) -> a -> b
$ \forall a. m a -> IO a
run ->
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
IO.withBinaryFile FilePath
fp IOMode
IO.WriteMode forall a b. (a -> b) -> a -> b
$ \Handle
h ->
forall a. m a -> IO a
run forall a b. (a -> b) -> a -> b
$ ConduitM Builder o n () -> m a
inner forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a o.
Monad m =>
(a -> m ()) -> ConduitT a o m ()
CL.mapM_ (forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO 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 =
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 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ DirStream -> IO (Maybe FilePath)
F.readDirStream DirStream
ds
case Maybe FilePath
mfp of
Maybe FilePath
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just FilePath
fp -> do
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield 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 =
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 = forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
sourceDirectory FilePath
dir forall (m :: * -> *) a b c r.
Monad m =>
ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
.| forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever 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 <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ FilePath -> IO FileType
F.getFileType FilePath
fp
case FileType
ft of
FileType
F.FTFile -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield FilePath
fp
FileType
F.FTFileSym -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield FilePath
fp
FileType
F.FTDirectory -> forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
start FilePath
fp
FileType
F.FTDirectorySym
| Bool
followSymlinks -> forall (m :: * -> *) i.
MonadResource m =>
FilePath -> ConduitT i FilePath m ()
start FilePath
fp
| Bool
otherwise -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
FileType
F.FTOther -> 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 =
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 forall a. Ord a => a -> a -> Bool
<= Index mono
0
then forall (m :: * -> *) a. Monad m => a -> m a
return ()
else forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (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
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull mono
y) forall a b. (a -> b) -> a -> b
$ 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) = forall seq. IsSequence seq => Index seq -> seq -> (seq, seq)
Seq.splitAt Index mono
i mono
sq
i' :: Index mono
i' = Index mono
i forall a. Num a => a -> a -> a
- forall a b. (Integral a, Num b) => a -> b
fromIntegral (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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) 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 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) seq -> ConduitT seq o m ()
go
go :: seq -> ConduitT seq o m ()
go seq
sq =
if forall mono. MonoFoldable mono => mono -> Bool
onull seq
x then ConduitT seq o m ()
loop else forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover seq
x
where
x :: seq
x = 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 = forall mono a.
MonoFoldable mono =>
(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 =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) a -> ConduitT a o m (Maybe a)
loop
where
loop :: a -> ConduitT a o m (Maybe a)
loop !a
prev = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just a
prev) (a -> ConduitT a o m (Maybe a)
loop 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, forall mono. MonoFoldable mono => mono -> Maybe (NonNull mono)
NonNull.fromNullable mono
mono) of
(Just e
acc, Just NonNull mono
nn) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall mono a.
MonoFoldable mono =>
(a -> Element mono -> a) -> a -> mono -> a
ofoldl' e -> e -> e
f e
acc NonNull mono
nn
(Maybe e
Nothing, Just NonNull mono
nn) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall mono.
MonoFoldable mono =>
(Element mono -> Element mono -> Element mono)
-> NonNull mono -> Element mono
NonNull.ofoldl1' e -> e -> e
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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Maybe a -> Bool
isNothing forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a o.
Monad m =>
(a -> Bool) -> ConduitT a o m (Maybe a)
find (Bool -> Bool
Prelude.not 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Maybe a -> Bool
isJust forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. 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 = (forall lazy strict. LazySequence lazy strict => [strict] -> lazy
fromChunks forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (forall a b. (a -> b) -> a -> b
$ [])) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (strict
nextforall a. 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 <- forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VM.new 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 forall a. Ord a => a -> a -> Bool
>= Int
maxSize = do
let newMax :: Int
newMax = Int
maxSize forall a. Num a => a -> a -> a
* Int
2
Mutable v (PrimState m) a
mv' <- 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
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 <- forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
case Maybe a
mx of
Maybe a
Nothing -> forall (v :: * -> *) a.
(HasCallStack, Vector v a) =>
Int -> Int -> v a -> v a
V.slice Int
0 Int
i forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState m) a
mv
Just a
x -> do
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VM.write Mutable v (PrimState 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 forall a. Num a => a -> a -> a
+ Int
1) Mutable v (PrimState m) a
mv
forall {m :: * -> *} {v :: * -> *} {a} {o}.
(PrimMonad m, Vector v a) =>
Int -> Int -> Mutable v (PrimState m) a -> ConduitT a o m (v a)
go 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 <- 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 forall a. Ord a => a -> a -> Bool
>= Int
maxSize = forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState m) a
mv
go Int
i = do
Maybe a
mx <- forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
case Maybe a
mx of
Maybe a
Nothing -> forall (v :: * -> *) a.
(HasCallStack, Vector v a) =>
Int -> Int -> v a -> v a
V.slice Int
0 Int
i forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState m) a
mv
Just a
x -> do
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VM.write Mutable v (PrimState m) a
mv Int
i a
x
Int -> ConduitT a o m (v a)
go (Int
i 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 = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Builder -> ByteString
toLazyByteString 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 =
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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) i -> ConduitT i o m (Maybe (NonNull i))
go'
go' :: i -> ConduitT i o m (Maybe (NonNull i))
go' = forall b a. b -> (a -> b) -> Maybe a -> b
maybe ConduitT i o m (Maybe (NonNull i))
go (forall (m :: * -> *) a. Monad m => a -> m a
return forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. a -> Maybe a
Just) forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. 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 = 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 = forall a. a -> Maybe a -> a
fromMaybe a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 =
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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) mono -> ConduitT mono o m (Maybe (Element mono))
go
go :: mono -> ConduitT mono o m (Maybe (Element mono))
go mono
x =
case 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
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull mono
z) forall a b. (a -> b) -> a -> b
$ forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
z
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ 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 = 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 =
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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) mono -> ConduitT mono o m (Maybe (Element mono))
go
go :: mono -> ConduitT mono o m (Maybe (Element mono))
go mono
x =
case 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
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ 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 =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ 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 = forall a. a -> Maybe a -> a
fromMaybe a
a forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 =
forall (m :: * -> *) a o.
(Monad m, MonoFoldable a) =>
ConduitT a o m (Maybe (NonNull a))
awaitNonNull forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) (forall {m :: * -> *} {a} {o}.
(Monad m, MonoFoldable a) =>
Element a -> ConduitT a o m (Maybe (Element a))
loop forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. 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 = forall (m :: * -> *) a o.
(Monad m, MonoFoldable a) =>
ConduitT a o m (Maybe (NonNull a))
awaitNonNull forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just Element a
prev) (Element a -> ConduitT a o m (Maybe (Element a))
loop forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. 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 = (forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (\a
_ -> Bool
False)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` 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 =
forall (m :: * -> *) mono o.
(Monad m, MonoFoldable mono) =>
ConduitT mono o m Bool
go
where
go :: ConduitT mono o m Bool
go = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True) mono -> ConduitT mono o m Bool
go'
go' :: mono -> ConduitT mono o m Bool
go' mono
x = if forall mono. MonoFoldable mono => mono -> Bool
onull mono
x then ConduitT mono o m Bool
go else forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover mono
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) a -> 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 forall (m :: * -> *) a. Monad m => a -> m a
return (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 = 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 = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (forall (m :: * -> *) mono i.
(Monad m, MonoFoldable mono) =>
mono -> ConduitT i (Element mono) m ()
yieldMany 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 =
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 forall a. Ord a => a -> a -> Bool
<= Index mono
0
then forall (m :: * -> *) a. Monad m => a -> m a
return ()
else forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (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
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull mono
x) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield mono
x
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull mono
y) forall a b. (a -> b) -> a -> b
$ 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) = forall seq. IsSequence seq => Index seq -> seq -> (seq, seq)
Seq.splitAt Index mono
i mono
sq
i' :: Index mono
i' = Index mono
i forall a. Num a => a -> a -> a
- forall a b. (Integral a, Num b) => a -> b
fromIntegral (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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) a -> ConduitT a a m ()
go
go :: a -> ConduitT a a m ()
go a
x = if a -> Bool
f a
x
then forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT a a m ()
loop
else 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) seq -> ConduitT seq seq m ()
go
go :: seq -> ConduitT seq seq m ()
go seq
sq = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull seq
x) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
x
if forall mono. MonoFoldable mono => mono -> Bool
onull seq
y
then ConduitT seq seq m ()
loop
else forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover seq
y
where
(seq
x, seq
y) = 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 = forall (m :: * -> *) a. Monad m => Int -> ConduitT a a m ()
take Int
count 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
forall (m :: * -> *) a o. Monad m => ConduitT a o m ()
CL.sinkNull
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 = forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
takeE Index a
count 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
forall (m :: * -> *) a o. Monad m => ConduitT a o m ()
CL.sinkNull
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 = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) 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 -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
y forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT a b m ()
loop
Maybe b
Nothing -> 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 <- forall (v :: * -> *) a (m :: * -> *) o.
(Vector v a, PrimMonad m) =>
Int -> ConduitT a o m (v a)
sinkVectorN Int
size
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall (v :: * -> *) a. Vector v a => v a -> Bool
V.null v a
v) forall a b. (a -> b) -> a -> b
$ do
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 =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
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' seq :: forall a b. a -> b -> b
`seq` 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return s
s) a -> ConduitT a b m s
go
where
go :: a -> ConduitT a b m s
go a
a = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$!) (\(s
s', b
b) -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> s -> ConduitT a b m s
loop s
s') 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ 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 = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (m :: * -> *) a. Monad m => a -> m a
return forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$!) s -> ConduitT a o m (Either e s)
loop 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 =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall mono (m :: * -> *).
(MonoFoldable mono, Applicative m) =>
(Element mono -> m ()) -> mono -> m ()
omapM_ a -> ConduitT a a m ()
go
where
go :: a -> ConduitT a a m ()
go a
y = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
y forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> 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 = forall {m :: * -> *} {t} {t}.
(Monad m, IsSequence t, Num t, Eq t) =>
t -> t -> ConduitT (Element t) t m ()
go (forall a. Ord a => a -> a -> a
max Int
1 Int
sz) forall a. Monoid a => a
mempty
where goContinue :: t -> ConduitT (Element t) t m ()
goContinue t
st = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ())
(\Element t
x -> do
let st' :: t
st' = forall seq. SemiSequence seq => seq -> Element seq -> seq
Seq.snoc t
st Element t
x
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield t
st' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> t -> ConduitT (Element t) t m ()
goContinue (forall seq. IsSequence seq => seq -> seq
Seq.unsafeTail t
st')
)
go :: t -> t -> ConduitT (Element t) t m ()
go t
0 t
st = forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield t
st forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {m :: * -> *} {t}.
(Monad m, IsSequence t) =>
t -> ConduitT (Element t) t m ()
goContinue (forall seq. IsSequence seq => seq -> seq
Seq.unsafeTail t
st)
go !t
n t
st = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
CL.head 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 -> 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
nforall a. Num a => a -> a -> a
-t
1) (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 = forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
chunksOfExactlyE Index seq
chunkSize forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall (m :: * -> *) 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) seq -> ConduitT seq seq m ()
start
where
start :: seq -> ConduitT seq seq m ()
start seq
b
| forall mono. MonoFoldable mono => mono -> Bool
onull seq
b = forall (m :: * -> *) seq.
(Monad m, IsSequence seq) =>
Index seq -> ConduitT seq seq m ()
chunksOfExactlyE Index seq
chunkSize
| forall seq. IsSequence seq => seq -> Index seq
Seq.lengthIndex seq
b forall a. Ord a => a -> a -> Bool
< Index seq
chunkSize = Index seq -> [seq] -> ConduitT seq seq m ()
continue (forall seq. IsSequence seq => seq -> Index seq
Seq.lengthIndex seq
b) [seq
b]
| Bool
otherwise = let (seq
first,seq
rest) = forall seq. IsSequence seq => Index seq -> seq -> (seq, seq)
Seq.splitAt Index seq
chunkSize seq
b in
forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
first 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 <- forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await
case Maybe seq
next of
Maybe seq
Nothing -> forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover (forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
Prelude.reverse [seq]
bs)
Just seq
next' ->
let !sofar' :: Index seq
sofar' = forall seq. IsSequence seq => seq -> Index seq
Seq.lengthIndex seq
next' forall a. Num a => a -> a -> a
+ Index seq
sofar
bs' :: [seq]
bs' = seq
next'forall a. a -> [a] -> [a]
:[seq]
bs
in if Index seq
sofar' 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 (forall a. Monoid a => [a] -> a
mconcat (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 = forall (m :: * -> *) i o r.
Monad m =>
(i -> ConduitT i o m r) -> ConduitT i o m ()
awaitForever (forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift 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 forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> 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 =
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 <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ a -> m Bool
f a
x
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
b forall a b. (a -> b) -> a -> b
$ 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 =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield a
seed) b -> ConduitT b a m ()
go
where
go :: b -> ConduitT b a m ()
go b
b = do
a
seed' <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ a -> b -> m a
f a
seed b
b
a
seed' seq :: forall a b. a -> b -> b
`seq` 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return s
s) a -> ConduitT a b m s
go
where
go :: a -> ConduitT a b m s
go a
a = 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) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$!) (\(s
s', b
b) -> forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield b
b forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> s -> ConduitT a b m s
loop s
s')
{-# 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 =
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 =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe ConduitT ByteString Text m ()
done ByteString -> ConduitT ByteString Text m ()
go
where
parse' :: ByteString -> Either UnicodeException Decoding
parse' = forall a. IO a -> a
unsafePerformIO forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall e a. Exception e => IO a -> IO (Either e a)
try forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall a. a -> IO a
evaluate 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' forall a. Monoid a => a
mempty of
Left UnicodeException
e -> forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (UnicodeException
e :: TEE.UnicodeException)
Right (TE.Some Text
t ByteString
bs ByteString -> Decoding
_) -> do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield Text
t)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield 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
forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover ByteString
bs
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (UnicodeException
e :: TEE.UnicodeException)
Right (TE.Some Text
t ByteString
_ ByteString -> Decoding
next) -> do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (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 =
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 =
forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe 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 forall a. Monoid a => a
mempty
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield Text
t)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) (forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield 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
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Text -> Bool
T.null Text
t) (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 = forall (m :: * -> *) seq o r.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq o m r -> ConduitT seq o m r
takeExactlyUntilE (forall a. Eq a => a -> a -> Bool
== Char
'\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 = forall (m :: * -> *) seq o r.
(Monad m, IsSequence seq) =>
(Element seq -> Bool) -> ConduitT seq o m r -> ConduitT seq o m r
takeExactlyUntilE (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 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
forall (m :: * -> *) a o. Monad m => ConduitT a o m ()
sinkNull
forall (m :: * -> *) a. Monad m => a -> m a
return r
x
where
loop :: ConduitT seq seq m ()
loop = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall mono (m :: * -> *).
(MonoFoldable mono, Applicative m) =>
(Element mono -> m ()) -> mono -> m ()
omapM_ seq -> ConduitT seq seq m ()
go
go :: seq -> ConduitT seq seq m ()
go seq
t =
if forall mono. MonoFoldable mono => mono -> Bool
onull seq
y
then forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
x forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT seq seq m ()
loop
else do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull seq
x) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield seq
x
let y' :: seq
y' = forall seq. IsSequence seq => Index seq -> seq -> seq
Seq.drop Index seq
1 seq
y
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull seq
y') forall a b. (a -> b) -> a -> b
$ forall i o (m :: * -> *). i -> ConduitT i o m ()
leftover seq
y'
where
(seq
x, seq
y) = 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 = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (([seq] -> [seq]) -> seq -> ConduitT seq seq m ()
loop 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 forall mono. MonoFoldable mono => mono -> Bool
onull seq
y
then do
Maybe seq
mt <- 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 = forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ [seq] -> [seq]
bldr [seq
t]
in forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall mono. MonoFoldable mono => mono -> Bool
onull seq
finalChunk) forall a b. (a -> b) -> a -> b
$ 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 forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (seq
tforall a. a -> [a] -> [a]
:)) seq
t'
else forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield (forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$ [seq] -> [seq]
bldr [seq
x]) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ([seq] -> [seq]) -> seq -> ConduitT seq seq m ()
loop forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id (forall seq. IsSequence seq => Index seq -> seq -> seq
Seq.drop Index seq
1 seq
y)
where
(seq
x, seq
y) = 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 = 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 = 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 =
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 =
forall (m :: * -> *).
PrimMonad m =>
m (Maybe (Flush Builder))
-> (Flush ByteString -> m ()) -> BufferAllocStrategy -> m ()
bbhelper (forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. a -> Flush a
Chunk) forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await) 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 = forall (m :: * -> *) a. Monad m => a -> m a
return ()
yield' (Chunk o
bs) = 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 = forall (m :: * -> *).
PrimMonad m =>
m (Maybe (Flush Builder))
-> (Flush ByteString -> m ()) -> BufferAllocStrategy -> m ()
bbhelper forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await 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) <- forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim forall a b. (a -> b) -> a -> b
$ BufferAllocStrategy -> IO (BuilderRecv, BuilderFinish)
newByteStringBuilderRecv BufferAllocStrategy
strat
let loop :: m ()
loop = m (Maybe (Flush Builder))
await' forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe m ()
finish' Flush Builder -> m ()
cont
finish' :: m ()
finish' = do
Maybe ByteString
mbs <- forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim BuilderFinish
finish
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return ()) (Flush ByteString -> m ()
yield' forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. 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 <- forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim forall a b. (a -> b) -> a -> b
$ BuilderRecv
recv Builder
builder
let cont' :: m ()
cont' = do
ByteString
bs <- forall (m1 :: * -> *) (m2 :: * -> *) a.
(PrimBase m1, PrimMonad m2) =>
m1 a -> m2 a
unsafePrimToPrim IO ByteString
popper
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (ByteString -> Bool
S.null ByteString
bs) forall a b. (a -> b) -> a -> b
$ do
Flush ByteString -> m ()
yield' (forall a. a -> Flush a
Chunk ByteString
bs)
m ()
cont'
m ()
cont'
case Flush Builder
fbuilder of
Flush Builder
Flush -> Flush ByteString -> m ()
yield' forall a. Flush a
Flush
Chunk Builder
_ -> 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 <- forall a. a -> IO (IORef a)
newIORef IO Buffer
ioBufInit
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 <- forall a. IORef a -> IO a
readIORef IORef (IO Buffer)
refBuf
Buffer
buf <- IO Buffer
ioBuf
forall (m :: * -> *) a. Monad m => a -> m a
return 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 <- forall a. a -> IO (IORef a)
newIORef forall a b. (a -> b) -> a -> b
$ forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ Builder -> BufferWriter
BB.runBuilder Builder
builder
forall (m :: * -> *) a. Monad m => a -> m a
return 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 <- forall a. IORef a -> IO a
readIORef IORef (IO Buffer)
refBuf
Either BufferWriter (IO ByteString)
ebWri <- 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 forall a b. Ptr a -> Ptr b -> Int
`minusPtr` Ptr Word8
op)
let op' :: Ptr Word8
op' = Ptr Word8
op forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
bytes
case Next
next of
Next
BB.Done -> do
forall a. IORef a -> a -> IO ()
writeIORef IORef (IO Buffer)
refBuf forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Buffer -> Ptr Word8 -> Buffer
updateEndOfSlice Buffer
buf Ptr Word8
op'
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'
forall a. IORef a -> a -> IO ()
writeIORef IORef (IO Buffer)
refBuf IO Buffer
ioBuf'
forall a. IORef a -> a -> IO ()
writeIORef IORef (Either BufferWriter (IO ByteString))
refWri forall a b. (a -> b) -> a -> b
$ forall a b. a -> Either a b
Left BufferWriter
bWri'
case Maybe ByteString
mbs of
Just ByteString
bs | Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ ByteString -> Bool
S.null ByteString
bs -> 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 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' forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. IORef a -> a -> IO ()
writeIORef IORef (IO Buffer)
refBuf
forall a. IORef a -> a -> IO ()
writeIORef IORef (Either BufferWriter (IO ByteString))
refWri forall a b. (a -> b) -> a -> b
$ 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 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
forall a. IORef a -> a -> IO ()
writeIORef IORef (Either BufferWriter (IO ByteString))
refWri forall a b. (a -> b) -> a -> b
$ forall a b. b -> Either a b
Right IO ByteString
yieldBS
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 forall a b. Ptr a -> Ptr b -> Int
`minusPtr` forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fpbuf) (Ptr Word8
op 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 forall a. Ord a => a -> a -> Bool
<= Int
0 = forall a. Maybe a
Nothing
| Bool
otherwise = forall a. a -> Maybe a
Just 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 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
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> IO Buffer
allocBuffer (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, 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 forall a. Ord a => a -> a -> Bool
>= Int
reqSize = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return (Buffer -> Buffer
reuseBuffer Buffer
buf)
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return 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 forall a b. Ptr a -> Ptr b -> Int
`minusPtr` 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 <- forall a. Int -> IO (ForeignPtr a)
mallocByteString Int
size
let !pbuf :: Ptr Word8
pbuf = forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fpbuf
forall (m :: * -> *) a. Monad m => a -> m a
return 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 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 = 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 <- forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VM.new Int
size
forall (m :: * -> *) a.
PrimMonad m =>
a -> m (MutVar (PrimState m) a)
newMutVar forall a b. (a -> b) -> a -> b
$! 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 forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
r
res <- forall (m :: * -> *) i o r.
Monad m =>
ConduitT i o m () -> ConduitT i Void m r -> ConduitT i o m r
onAwait (forall (m :: * -> *) (v :: * -> *) e i.
PrimMonad m =>
MutVar (PrimState m) (S (PrimState m) v e) -> ConduitT i (v e) m ()
yieldS MutVar (PrimState n) (S (PrimState n) v e)
ref) ((e -> n ()) -> ConduitT i Void m r
inner (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 <- forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar (PrimState n) (S (PrimState n) v e)
ref
[v e]
end <-
if Int
idx forall a. Eq a => a -> a -> Bool
== Int
0
then forall (m :: * -> *) a. Monad m => a -> m a
return []
else do
v e
v <- forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState n) e
mv
forall (m :: * -> *) a. Monad m => a -> m a
return [forall (v :: * -> *) a. Vector v a => Int -> v a -> v a
V.unsafeTake Int
idx v e
v]
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [v e] -> [v e]
front [v e]
end
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
Prelude.mapM_ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield [v e]
vs
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 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 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) = forall a. Void -> a
absurd Void
o
go (NeedInput i -> Pipe i i Void () m r
f () -> Pipe i i Void () m r
g) = forall b. (() -> Pipe i i o () m b) -> Pipe i i o () m b
callback forall a b. (a -> b) -> a -> 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 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 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) = forall l i o u (m :: * -> *) r.
m (Pipe l i o u m r) -> Pipe l i o u m r
PipeM (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) = 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 (forall b. (r -> Pipe i i Void () m b) -> Pipe i i Void () m b
sink0 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
S Int
idx Mutable v (PrimState m) e
mv [v e] -> [v e]
front <- forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar (PrimState m) (S (PrimState m) v e)
ref
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
Prelude.mapM_ forall (m :: * -> *) o i. Monad m => o -> ConduitT i o m ()
yield ([v e] -> [v e]
front [])
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> a -> m ()
writeMutVar MutVar (PrimState m) (S (PrimState m) v e)
ref forall a b. (a -> b) -> a -> b
$! forall s (v :: * -> *) e.
Int -> Mutable v s e -> ([v e] -> [v e]) -> S s v e
S Int
idx Mutable v (PrimState m) e
mv forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
{-# INLINE yieldS #-}
addE :: (PrimMonad m, V.Vector v e)
=> MutVar (PrimState m) (S (PrimState m) v e)
-> e
-> m ()
addE :: forall (m :: * -> *) (v :: * -> *) e.
(PrimMonad m, Vector v e) =>
MutVar (PrimState m) (S (PrimState m) v e) -> e -> m ()
addE MutVar (PrimState m) (S (PrimState m) v e)
ref e
e = do
S Int
idx Mutable v (PrimState m) e
mv [v e] -> [v e]
front <- forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> m a
readMutVar MutVar (PrimState m) (S (PrimState m) v e)
ref
forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
v (PrimState m) a -> Int -> a -> m ()
VM.write Mutable v (PrimState m) e
mv Int
idx e
e
let idx' :: Int
idx' = forall a. Enum a => a -> a
succ Int
idx
size :: Int
size = forall (v :: * -> * -> *) a s. MVector v a => v s a -> Int
VM.length Mutable v (PrimState m) e
mv
if Int
idx' forall a. Ord a => a -> a -> Bool
>= Int
size
then do
v e
v <- forall (m :: * -> *) (v :: * -> *) a.
(PrimMonad m, Vector v a) =>
Mutable v (PrimState m) a -> m (v a)
V.unsafeFreeze Mutable v (PrimState m) e
mv
let front' :: [v e] -> [v e]
front' = [v e] -> [v e]
front forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (v e
vforall a. a -> [a] -> [a]
:)
Mutable v (PrimState m) e
mv' <- forall (m :: * -> *) (v :: * -> * -> *) a.
(HasCallStack, PrimMonad m, MVector v a) =>
Int -> m (v (PrimState m) a)
VM.new Int
size
forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> a -> m ()
writeMutVar MutVar (PrimState m) (S (PrimState m) v e)
ref forall a b. (a -> b) -> a -> b
$! forall s (v :: * -> *) e.
Int -> Mutable v s e -> ([v e] -> [v e]) -> S s v e
S Int
0 Mutable v (PrimState m) e
mv' [v e] -> [v e]
front'
else forall (m :: * -> *) a.
PrimMonad m =>
MutVar (PrimState m) a -> a -> m ()
writeMutVar MutVar (PrimState m) (S (PrimState m) v e)
ref forall a b. (a -> b) -> a -> b
$! forall s (v :: * -> *) e.
Int -> Mutable v s e -> ([v e] -> [v e]) -> S s v e
S Int
idx' Mutable v (PrimState m) e
mv [v e] -> [v e]
front
{-# INLINE addE #-}
mapAccumS
:: Monad m
=> (a -> s -> ConduitT b Void m s)
-> s
-> ConduitT () b m ()
-> ConduitT a Void m s
mapAccumS :: forall (m :: * -> *) a s b.
Monad m =>
(a -> s -> ConduitT b Void m s)
-> s -> ConduitT () b m () -> ConduitT a Void m s
mapAccumS a -> s -> ConduitT b Void m s
f s
s ConduitT () b m ()
xs = do
(SealedConduitT () b m ()
_, s
u) <- (SealedConduitT () b m (), s)
-> ConduitT a Void m (SealedConduitT () b m (), s)
loop (forall i o (m :: * -> *) r.
ConduitT i o m r -> SealedConduitT i o m r
sealConduitT ConduitT () b m ()
xs, s
s)
forall (m :: * -> *) a. Monad m => a -> m a
return s
u
where loop :: (SealedConduitT () b m (), s)
-> ConduitT a Void m (SealedConduitT () b m (), s)
loop r :: (SealedConduitT () b m (), s)
r@(SealedConduitT () b m ()
ys, !s
t) = forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
await forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return (SealedConduitT () b m (), s)
r) a -> ConduitT a Void m (SealedConduitT () b m (), s)
go
where go :: a -> ConduitT a Void m (SealedConduitT () b m (), s)
go a
a = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (SealedConduitT () b m ()
ys forall (m :: * -> *) a b.
Monad m =>
SealedConduitT () a m ()
-> ConduitT a Void m b -> m (SealedConduitT () a m (), b)
$$++ a -> s -> ConduitT b Void m s
f a
a s
t) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (SealedConduitT () b m (), s)
-> ConduitT a Void m (SealedConduitT () b m (), s)
loop
{-# INLINE mapAccumS #-}
peekForever :: Monad m => ConduitT i o m () -> ConduitT i o m ()
peekForever :: forall (m :: * -> *) i o.
Monad m =>
ConduitT i o m () -> ConduitT i o m ()
peekForever ConduitT i o m ()
inner =
ConduitT i o m ()
loop
where
loop :: ConduitT i o m ()
loop = do
Maybe i
mx <- forall (m :: * -> *) i o. Monad m => ConduitT i o m (Maybe i)
peek
case Maybe i
mx of
Maybe i
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just i
_ -> ConduitT i o m ()
inner forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT i o m ()
loop
peekForeverE :: (Monad m, MonoFoldable i)
=> ConduitT i o m ()
-> ConduitT i o m ()
peekForeverE :: forall (m :: * -> *) i o.
(Monad m, MonoFoldable i) =>
ConduitT i o m () -> ConduitT i o m ()
peekForeverE ConduitT i o m ()
inner =
ConduitT i o m ()
loop
where
loop :: ConduitT i o m ()
loop = do
Maybe (Element i)
mx <- forall (m :: * -> *) mono o.
(Monad m, MonoFoldable mono) =>
ConduitT mono o m (Maybe (Element mono))
peekE
case Maybe (Element i)
mx of
Maybe (Element i)
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just Element i
_ -> ConduitT i o m ()
inner forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ConduitT i o m ()
loop