{-# LANGUAGE RankNTypes, Trustworthy #-}
module Pipes.ByteString (
fromLazy
, stdin
, fromHandle
, hGetSome
, hGetNonBlocking
, hGet
, hGetRange
, hGetSomeN
, hGetN
, stdout
, toHandle
, map
, concatMap
, take
, takeWhile
, filter
, elemIndices
, findIndices
, scan
, toLazy
, toLazyM
, toLazyM'
, foldBytes
, head
, last
, null
, length
, any
, all
, maximum
, minimum
, elem
, notElem
, find
, index
, elemIndex
, findIndex
, count
, nextByte
, drawByte
, unDrawByte
, peekByte
, isEndOfBytes
, splitAt
, span
, break
, breakOn
, groupBy
, group
, word
, line
, drop
, dropWhile
, intersperse
, pack
, unpack
, chunksOf'
, chunksOf
, splitsWith
, splits
, splitOn
, groupsBy
, groups
, lines
, unlines
, words
, unwords
, module Data.ByteString
, module Data.Word
, module Pipes.Group
, module Pipes.Parse
) where
import Control.Applicative ((<*))
import Control.Exception (throwIO, try)
import Control.Monad (liftM, join)
import Control.Monad.Trans.State.Strict (modify)
import qualified Data.ByteString as BS
import Data.ByteString (ByteString)
import Data.ByteString.Internal (isSpaceWord8)
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Search
import Data.ByteString.Lazy.Internal (foldrChunks, defaultChunkSize)
import Data.ByteString.Unsafe (unsafeTake)
import Data.Char (ord)
import Data.Monoid (mempty, (<>))
import Data.Functor.Constant (Constant(Constant, getConstant))
import Data.Functor.Identity (Identity)
import qualified Data.List as List
import Data.Word (Word8)
import Foreign.C.Error (Errno(Errno), ePIPE)
import qualified GHC.IO.Exception as G
import Pipes
import Pipes.Core (respond, Server')
import qualified Pipes.Group as PG
import Pipes.Group (concats, intercalates, FreeT)
import qualified Pipes.Parse as PP
import Pipes.Parse (Parser)
import qualified Pipes.Prelude as P
import qualified System.IO as IO
import Prelude hiding (
all
, any
, break
, concatMap
, drop
, dropWhile
, elem
, filter
, head
, last
, lines
, length
, map
, maximum
, minimum
, notElem
, null
, span
, splitAt
, take
, takeWhile
, unlines
, unwords
, words
)
fromLazy :: Monad m => BL.ByteString -> Producer' ByteString m ()
fromLazy :: ByteString -> Producer' ByteString m ()
fromLazy ByteString
bs = (ByteString
-> Proxy x' x () ByteString m () -> Proxy x' x () ByteString m ())
-> Proxy x' x () ByteString m ()
-> ByteString
-> Proxy x' x () ByteString m ()
forall a. (ByteString -> a -> a) -> a -> ByteString -> a
foldrChunks (\ByteString
e Proxy x' x () ByteString m ()
a -> ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
e Proxy x' x () ByteString m ()
-> Proxy x' x () ByteString m () -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Proxy x' x () ByteString m ()
a) (() -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) ByteString
bs
{-# INLINABLE fromLazy #-}
stdin :: MonadIO m => Producer' ByteString m ()
stdin :: Producer' ByteString m ()
stdin = Handle -> Producer' ByteString m ()
forall (m :: * -> *).
MonadIO m =>
Handle -> Producer' ByteString m ()
fromHandle Handle
IO.stdin
{-# INLINABLE stdin #-}
fromHandle :: MonadIO m => IO.Handle -> Producer' ByteString m ()
fromHandle :: Handle -> Producer' ByteString m ()
fromHandle = Int -> Handle -> Producer' ByteString m ()
forall (m :: * -> *).
MonadIO m =>
Int -> Handle -> Producer' ByteString m ()
hGetSome Int
defaultChunkSize
{-# INLINABLE fromHandle #-}
hGetSome :: MonadIO m => Int -> IO.Handle -> Producer' ByteString m ()
hGetSome :: Int -> Handle -> Producer' ByteString m ()
hGetSome Int
size Handle
h = Proxy x' x () ByteString m ()
Producer' ByteString m ()
go
where
go :: Proxy x' x () ByteString m ()
go = do
ByteString
bs <- IO ByteString -> Proxy x' x () ByteString m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Handle -> Int -> IO ByteString
BS.hGetSome Handle
h Int
size)
if (ByteString -> Bool
BS.null ByteString
bs)
then () -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs
Proxy x' x () ByteString m ()
go
{-# INLINABLE hGetSome #-}
hGetNonBlocking :: MonadIO m => Int -> IO.Handle -> Producer' ByteString m ()
hGetNonBlocking :: Int -> Handle -> Producer' ByteString m ()
hGetNonBlocking Int
size Handle
h = Proxy x' x () ByteString m ()
Producer' ByteString m ()
go where
go :: Proxy x' x () ByteString m ()
go = do
Bool
eof <- IO Bool -> Proxy x' x () ByteString m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Handle -> IO Bool
IO.hIsEOF Handle
h)
if Bool
eof
then () -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do
ByteString
bs <- IO ByteString -> Proxy x' x () ByteString m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Handle -> Int -> IO ByteString
BS.hGetNonBlocking Handle
h Int
size)
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs
Proxy x' x () ByteString m ()
go
{-# INLINABLE hGetNonBlocking #-}
hGet :: MonadIO m => Int -> IO.Handle -> Producer' ByteString m ()
hGet :: Int -> Handle -> Producer' ByteString m ()
hGet Int
size Handle
h = Proxy x' x () ByteString m ()
Producer' ByteString m ()
go
where
go :: Proxy x' x () ByteString m ()
go = do
ByteString
bs <- IO ByteString -> Proxy x' x () ByteString m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Handle -> Int -> IO ByteString
BS.hGet Handle
h Int
size)
if (ByteString -> Bool
BS.null ByteString
bs)
then () -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs
Proxy x' x () ByteString m ()
go
{-# INLINABLE hGet #-}
hGetRange
:: MonadIO m
=> Int
-> Int
-> IO.Handle
-> Producer' ByteString m ()
hGetRange :: Int -> Int -> Handle -> Producer' ByteString m ()
hGetRange Int
offset Int
size Handle
h = do
IO () -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Proxy x' x () ByteString m ())
-> IO () -> Proxy x' x () ByteString m ()
forall a b. (a -> b) -> a -> b
$ Handle -> SeekMode -> Integer -> IO ()
IO.hSeek Handle
h SeekMode
IO.AbsoluteSeek (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
offset)
Int -> Handle -> Producer' ByteString m ()
forall (m :: * -> *).
MonadIO m =>
Int -> Handle -> Producer' ByteString m ()
hGet Int
size Handle
h
{-# INLINABLE hGetRange #-}
(^.) :: a -> ((b -> Constant b b) -> (a -> Constant b a)) -> b
a
a ^. :: a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^. (b -> Constant b b) -> a -> Constant b a
lens = Constant b a -> b
forall a k (b :: k). Constant a b -> a
getConstant ((b -> Constant b b) -> a -> Constant b a
lens b -> Constant b b
forall k a (b :: k). a -> Constant a b
Constant a
a)
hGetSomeN :: MonadIO m => IO.Handle -> Int -> Server' Int ByteString m ()
hGetSomeN :: Handle -> Int -> Server' Int ByteString m ()
hGetSomeN Handle
h Int
size = Int -> Proxy x' x Int ByteString m ()
forall (m :: * -> *) x' x.
MonadIO m =>
Int -> Proxy x' x Int ByteString m ()
go Int
size
where
go :: Int -> Proxy x' x Int ByteString m ()
go Int
size = do
ByteString
bs <- IO ByteString -> Proxy x' x Int ByteString m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Handle -> Int -> IO ByteString
BS.hGetSome Handle
h Int
size)
if (ByteString -> Bool
BS.null ByteString
bs)
then () -> Proxy x' x Int ByteString m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do
Int
size2 <- ByteString -> Proxy x' x Int ByteString m Int
forall (m :: * -> *) a x' x a'.
Functor m =>
a -> Proxy x' x a' a m a'
respond ByteString
bs
Int -> Proxy x' x Int ByteString m ()
go Int
size2
{-# INLINABLE hGetSomeN #-}
hGetN :: MonadIO m => IO.Handle -> Int -> Server' Int ByteString m ()
hGetN :: Handle -> Int -> Server' Int ByteString m ()
hGetN Handle
h Int
size = Int -> Proxy x' x Int ByteString m ()
forall (m :: * -> *) x' x.
MonadIO m =>
Int -> Proxy x' x Int ByteString m ()
go Int
size
where
go :: Int -> Proxy x' x Int ByteString m ()
go Int
size = do
ByteString
bs <- IO ByteString -> Proxy x' x Int ByteString m ByteString
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Handle -> Int -> IO ByteString
BS.hGet Handle
h Int
size)
if (ByteString -> Bool
BS.null ByteString
bs)
then () -> Proxy x' x Int ByteString m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
else do
Int
size2 <- ByteString -> Proxy x' x Int ByteString m Int
forall (m :: * -> *) a x' x a'.
Functor m =>
a -> Proxy x' x a' a m a'
respond ByteString
bs
Int -> Proxy x' x Int ByteString m ()
go Int
size2
{-# INLINABLE hGetN #-}
stdout :: MonadIO m => Consumer' ByteString m ()
stdout :: Consumer' ByteString m ()
stdout = Proxy () ByteString y' y m ()
Consumer' ByteString m ()
go
where
go :: Proxy () ByteString y' y m ()
go = do
ByteString
bs <- Proxy () ByteString y' y m ByteString
forall (m :: * -> *) a. Functor m => Consumer' a m a
await
Either IOException ()
x <- IO (Either IOException ())
-> Proxy () ByteString y' y m (Either IOException ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either IOException ())
-> Proxy () ByteString y' y m (Either IOException ()))
-> IO (Either IOException ())
-> Proxy () ByteString y' y m (Either IOException ())
forall a b. (a -> b) -> a -> b
$ IO () -> IO (Either IOException ())
forall e a. Exception e => IO a -> IO (Either e a)
try (ByteString -> IO ()
BS.putStr ByteString
bs)
case Either IOException ()
x of
Left (G.IOError { ioe_type :: IOException -> IOErrorType
G.ioe_type = IOErrorType
G.ResourceVanished
, ioe_errno :: IOException -> Maybe CInt
G.ioe_errno = Just CInt
ioe })
| CInt -> Errno
Errno CInt
ioe Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePIPE
-> () -> Proxy () ByteString y' y m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Left IOException
e -> IO () -> Proxy () ByteString y' y m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO IOException
e)
Right () -> Proxy () ByteString y' y m ()
go
{-# INLINABLE stdout #-}
toHandle :: MonadIO m => IO.Handle -> Consumer' ByteString m r
toHandle :: Handle -> Consumer' ByteString m r
toHandle Handle
h = Proxy () ByteString () ByteString m r
-> (ByteString -> Proxy () ByteString y' y m ())
-> Proxy () ByteString y' y m r
forall (m :: * -> *) x' x b' b a' c' c.
Functor m =>
Proxy x' x b' b m a'
-> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a'
for Proxy () ByteString () ByteString m r
forall (m :: * -> *) a r. Functor m => Pipe a a m r
cat (IO () -> Proxy () ByteString y' y m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> Proxy () ByteString y' y m ())
-> (ByteString -> IO ())
-> ByteString
-> Proxy () ByteString y' y m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
BS.hPut Handle
h)
{-# INLINABLE [1] toHandle #-}
{-# RULES "p >-> toHandle h" forall p h .
p >-> toHandle h = for p (\bs -> liftIO (BS.hPut h bs))
#-}
map :: Monad m => (Word8 -> Word8) -> Pipe ByteString ByteString m r
map :: (Word8 -> Word8) -> Pipe ByteString ByteString m r
map Word8 -> Word8
f = (ByteString -> ByteString) -> Pipe ByteString ByteString m r
forall (m :: * -> *) a b r. Functor m => (a -> b) -> Pipe a b m r
P.map ((Word8 -> Word8) -> ByteString -> ByteString
BS.map Word8 -> Word8
f)
{-# INLINE map #-}
concatMap :: Monad m => (Word8 -> ByteString) -> Pipe ByteString ByteString m r
concatMap :: (Word8 -> ByteString) -> Pipe ByteString ByteString m r
concatMap Word8 -> ByteString
f = (ByteString -> ByteString) -> Pipe ByteString ByteString m r
forall (m :: * -> *) a b r. Functor m => (a -> b) -> Pipe a b m r
P.map ((Word8 -> ByteString) -> ByteString -> ByteString
BS.concatMap Word8 -> ByteString
f)
{-# INLINABLE concatMap #-}
take :: (Monad m, Integral n) => n -> Pipe ByteString ByteString m ()
take :: n -> Pipe ByteString ByteString m ()
take n
n0 = n -> Pipe ByteString ByteString m ()
forall t (m :: * -> *).
(Functor m, Integral t) =>
t -> Proxy () ByteString () ByteString m ()
go n
n0 where
go :: t -> Proxy () ByteString () ByteString m ()
go t
n
| t
n t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
0 = () -> Proxy () ByteString () ByteString m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = do
ByteString
bs <- Proxy () ByteString () ByteString m ByteString
forall (m :: * -> *) a. Functor m => Consumer' a m a
await
let len :: t
len = Int -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length ByteString
bs)
if (t
len t -> t -> Bool
forall a. Ord a => a -> a -> Bool
> t
n)
then ByteString -> Proxy () ByteString () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Int -> ByteString -> ByteString
unsafeTake (t -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
n) ByteString
bs)
else do
ByteString -> Proxy () ByteString () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs
t -> Proxy () ByteString () ByteString m ()
go (t
n t -> t -> t
forall a. Num a => a -> a -> a
- t
len)
{-# INLINABLE take #-}
takeWhile :: Monad m => (Word8 -> Bool) -> Pipe ByteString ByteString m ()
takeWhile :: (Word8 -> Bool) -> Pipe ByteString ByteString m ()
takeWhile Word8 -> Bool
predicate = Pipe ByteString ByteString m ()
go
where
go :: Pipe ByteString ByteString m ()
go = do
ByteString
bs <- Proxy () ByteString () ByteString m ByteString
forall (m :: * -> *) a. Functor m => Consumer' a m a
await
let (ByteString
prefix, ByteString
suffix) = (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
BS.span Word8 -> Bool
predicate ByteString
bs
if (ByteString -> Bool
BS.null ByteString
suffix)
then do
ByteString -> Pipe ByteString ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs
Pipe ByteString ByteString m ()
go
else ByteString -> Pipe ByteString ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
prefix
{-# INLINABLE takeWhile #-}
filter :: Monad m => (Word8 -> Bool) -> Pipe ByteString ByteString m r
filter :: (Word8 -> Bool) -> Pipe ByteString ByteString m r
filter Word8 -> Bool
predicate = (ByteString -> ByteString) -> Pipe ByteString ByteString m r
forall (m :: * -> *) a b r. Functor m => (a -> b) -> Pipe a b m r
P.map ((Word8 -> Bool) -> ByteString -> ByteString
BS.filter Word8 -> Bool
predicate)
{-# INLINABLE filter #-}
elemIndices :: (Monad m, Num n) => Word8 -> Pipe ByteString n m r
elemIndices :: Word8 -> Pipe ByteString n m r
elemIndices Word8
w8 = (Word8 -> Bool) -> Pipe ByteString n m r
forall (m :: * -> *) n r.
(Monad m, Num n) =>
(Word8 -> Bool) -> Pipe ByteString n m r
findIndices (Word8
w8 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
==)
{-# INLINABLE elemIndices #-}
findIndices :: (Monad m, Num n) => (Word8 -> Bool) -> Pipe ByteString n m r
findIndices :: (Word8 -> Bool) -> Pipe ByteString n m r
findIndices Word8 -> Bool
predicate = n -> Pipe ByteString n m r
forall (m :: * -> *) a b.
(Functor m, Num a) =>
a -> Proxy () ByteString () a m b
go n
0
where
go :: a -> Proxy () ByteString () a m b
go a
n = do
ByteString
bs <- Proxy () ByteString () a m ByteString
forall (m :: * -> *) a. Functor m => Consumer' a m a
await
[a] -> Proxy () ByteString () a m ()
forall (m :: * -> *) (f :: * -> *) a x' x.
(Functor m, Foldable f) =>
f a -> Proxy x' x () a m ()
each ([a] -> Proxy () ByteString () a m ())
-> [a] -> Proxy () ByteString () a m ()
forall a b. (a -> b) -> a -> b
$ (Int -> a) -> [Int] -> [a]
forall a b. (a -> b) -> [a] -> [b]
List.map (\Int
i -> a
n a -> a -> a
forall a. Num a => a -> a -> a
+ Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i) ((Word8 -> Bool) -> ByteString -> [Int]
BS.findIndices Word8 -> Bool
predicate ByteString
bs)
a -> Proxy () ByteString () a m b
go (a -> Proxy () ByteString () a m b)
-> a -> Proxy () ByteString () a m b
forall a b. (a -> b) -> a -> b
$! a
n a -> a -> a
forall a. Num a => a -> a -> a
+ Int -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length ByteString
bs)
{-# INLINABLE findIndices #-}
scan
:: Monad m
=> (Word8 -> Word8 -> Word8) -> Word8 -> Pipe ByteString ByteString m r
scan :: (Word8 -> Word8 -> Word8)
-> Word8 -> Pipe ByteString ByteString m r
scan Word8 -> Word8 -> Word8
step Word8
begin = do
ByteString -> Proxy () ByteString () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Word8 -> ByteString
BS.singleton Word8
begin)
Word8 -> Pipe ByteString ByteString m r
forall (m :: * -> *) b.
Functor m =>
Word8 -> Proxy () ByteString () ByteString m b
go Word8
begin
where
go :: Word8 -> Proxy () ByteString () ByteString m b
go Word8
w8 = do
ByteString
bs <- Proxy () ByteString () ByteString m ByteString
forall (m :: * -> *) a. Functor m => Consumer' a m a
await
let bs' :: ByteString
bs' = (Word8 -> Word8 -> Word8) -> Word8 -> ByteString -> ByteString
BS.scanl Word8 -> Word8 -> Word8
step Word8
w8 ByteString
bs
w8' :: Word8
w8' = ByteString -> Word8
BS.last ByteString
bs'
ByteString -> Proxy () ByteString () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (ByteString -> ByteString
BS.tail ByteString
bs')
Word8 -> Proxy () ByteString () ByteString m b
go Word8
w8'
{-# INLINABLE scan #-}
toLazy :: Producer ByteString Identity () -> BL.ByteString
toLazy :: Producer ByteString Identity () -> ByteString
toLazy = [ByteString] -> ByteString
BL.fromChunks ([ByteString] -> ByteString)
-> (Producer ByteString Identity () -> [ByteString])
-> Producer ByteString Identity ()
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Producer ByteString Identity () -> [ByteString]
forall a. Producer a Identity () -> [a]
P.toList
{-# INLINABLE toLazy #-}
toLazyM :: Monad m => Producer ByteString m () -> m BL.ByteString
toLazyM :: Producer ByteString m () -> m ByteString
toLazyM = ([ByteString] -> ByteString) -> m [ByteString] -> m ByteString
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM [ByteString] -> ByteString
BL.fromChunks (m [ByteString] -> m ByteString)
-> (Producer ByteString m () -> m [ByteString])
-> Producer ByteString m ()
-> m ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Producer ByteString m () -> m [ByteString]
forall (m :: * -> *) a. Monad m => Producer a m () -> m [a]
P.toListM
{-# INLINABLE toLazyM #-}
toLazyM' :: Monad m => Producer ByteString m a -> m (BL.ByteString, a)
toLazyM' :: Producer ByteString m a -> m (ByteString, a)
toLazyM' Producer ByteString m a
p = do ([ByteString]
chunks, a
a) <- Producer ByteString m a -> m ([ByteString], a)
forall (m :: * -> *) a r. Monad m => Producer a m r -> m ([a], r)
P.toListM' Producer ByteString m a
p
(ByteString, a) -> m (ByteString, a)
forall (m :: * -> *) a. Monad m => a -> m a
return ([ByteString] -> ByteString
BL.fromChunks [ByteString]
chunks, a
a)
{-# INLINABLE toLazyM' #-}
foldBytes
:: Monad m
=> (x -> Word8 -> x) -> x -> (x -> r) -> Producer ByteString m () -> m r
foldBytes :: (x -> Word8 -> x)
-> x -> (x -> r) -> Producer ByteString m () -> m r
foldBytes x -> Word8 -> x
step x
begin x -> r
done = (x -> ByteString -> x)
-> x -> (x -> r) -> Producer ByteString m () -> m r
forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b
P.fold (\x
x ByteString
bs -> (x -> Word8 -> x) -> x -> ByteString -> x
forall a. (a -> Word8 -> a) -> a -> ByteString -> a
BS.foldl' x -> Word8 -> x
step x
x ByteString
bs) x
begin x -> r
done
{-# INLINABLE foldBytes #-}
head :: Monad m => Producer ByteString m () -> m (Maybe Word8)
head :: Producer ByteString m () -> m (Maybe Word8)
head = Producer ByteString m () -> m (Maybe Word8)
forall (m :: * -> *) r.
Monad m =>
Producer ByteString m r -> m (Maybe Word8)
go
where
go :: Producer ByteString m r -> m (Maybe Word8)
go Producer ByteString m r
p = do
Either r (Word8, Producer ByteString m r)
x <- Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
forall (m :: * -> *) r.
Monad m =>
Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
nextByte Producer ByteString m r
p
Maybe Word8 -> m (Maybe Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Word8 -> m (Maybe Word8)) -> Maybe Word8 -> m (Maybe Word8)
forall a b. (a -> b) -> a -> b
$ case Either r (Word8, Producer ByteString m r)
x of
Left r
_ -> Maybe Word8
forall a. Maybe a
Nothing
Right (Word8
w8, Producer ByteString m r
_) -> Word8 -> Maybe Word8
forall a. a -> Maybe a
Just Word8
w8
{-# INLINABLE head #-}
last :: Monad m => Producer ByteString m () -> m (Maybe Word8)
last :: Producer ByteString m () -> m (Maybe Word8)
last = Maybe Word8 -> Producer ByteString m () -> m (Maybe Word8)
forall (m :: * -> *).
Monad m =>
Maybe Word8 -> Producer ByteString m () -> m (Maybe Word8)
go Maybe Word8
forall a. Maybe a
Nothing
where
go :: Maybe Word8 -> Producer ByteString m () -> m (Maybe Word8)
go Maybe Word8
r Producer ByteString m ()
p = do
Either () (ByteString, Producer ByteString m ())
x <- Producer ByteString m ()
-> m (Either () (ByteString, Producer ByteString m ()))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m ()
p
case Either () (ByteString, Producer ByteString m ())
x of
Left () -> Maybe Word8 -> m (Maybe Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Word8
r
Right (ByteString
bs, Producer ByteString m ()
p') ->
Maybe Word8 -> Producer ByteString m () -> m (Maybe Word8)
go (if ByteString -> Bool
BS.null ByteString
bs then Maybe Word8
r else (Word8 -> Maybe Word8
forall a. a -> Maybe a
Just (Word8 -> Maybe Word8) -> Word8 -> Maybe Word8
forall a b. (a -> b) -> a -> b
$ ByteString -> Word8
BS.last ByteString
bs)) Producer ByteString m ()
p'
{-# INLINABLE last #-}
null :: Monad m => Producer ByteString m () -> m Bool
null :: Producer ByteString m () -> m Bool
null = (ByteString -> Bool) -> Producer ByteString m () -> m Bool
forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Producer a m () -> m Bool
P.all ByteString -> Bool
BS.null
{-# INLINABLE null #-}
length :: (Monad m, Num n) => Producer ByteString m () -> m n
length :: Producer ByteString m () -> m n
length = (n -> ByteString -> n)
-> n -> (n -> n) -> Producer ByteString m () -> m n
forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b
P.fold (\n
n ByteString
bs -> n
n n -> n -> n
forall a. Num a => a -> a -> a
+ Int -> n
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length ByteString
bs)) n
0 n -> n
forall a. a -> a
id
{-# INLINABLE length #-}
any :: Monad m => (Word8 -> Bool) -> Producer ByteString m () -> m Bool
any :: (Word8 -> Bool) -> Producer ByteString m () -> m Bool
any Word8 -> Bool
predicate = (ByteString -> Bool) -> Producer ByteString m () -> m Bool
forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Producer a m () -> m Bool
P.any ((Word8 -> Bool) -> ByteString -> Bool
BS.any Word8 -> Bool
predicate)
{-# INLINABLE any #-}
all :: Monad m => (Word8 -> Bool) -> Producer ByteString m () -> m Bool
all :: (Word8 -> Bool) -> Producer ByteString m () -> m Bool
all Word8 -> Bool
predicate = (ByteString -> Bool) -> Producer ByteString m () -> m Bool
forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Producer a m () -> m Bool
P.all ((Word8 -> Bool) -> ByteString -> Bool
BS.all Word8 -> Bool
predicate)
{-# INLINABLE all #-}
maximum :: Monad m => Producer ByteString m () -> m (Maybe Word8)
maximum :: Producer ByteString m () -> m (Maybe Word8)
maximum = (Maybe Word8 -> ByteString -> Maybe Word8)
-> Maybe Word8
-> (Maybe Word8 -> Maybe Word8)
-> Producer ByteString m ()
-> m (Maybe Word8)
forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b
P.fold Maybe Word8 -> ByteString -> Maybe Word8
step Maybe Word8
forall a. Maybe a
Nothing Maybe Word8 -> Maybe Word8
forall a. a -> a
id
where
step :: Maybe Word8 -> ByteString -> Maybe Word8
step Maybe Word8
mw8 ByteString
bs =
if (ByteString -> Bool
BS.null ByteString
bs)
then Maybe Word8
mw8
else Word8 -> Maybe Word8
forall a. a -> Maybe a
Just (Word8 -> Maybe Word8) -> Word8 -> Maybe Word8
forall a b. (a -> b) -> a -> b
$ case Maybe Word8
mw8 of
Maybe Word8
Nothing -> ByteString -> Word8
BS.maximum ByteString
bs
Just Word8
w8 -> Word8 -> Word8 -> Word8
forall a. Ord a => a -> a -> a
max Word8
w8 (ByteString -> Word8
BS.maximum ByteString
bs)
{-# INLINABLE maximum #-}
minimum :: Monad m => Producer ByteString m () -> m (Maybe Word8)
minimum :: Producer ByteString m () -> m (Maybe Word8)
minimum = (Maybe Word8 -> ByteString -> Maybe Word8)
-> Maybe Word8
-> (Maybe Word8 -> Maybe Word8)
-> Producer ByteString m ()
-> m (Maybe Word8)
forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b
P.fold Maybe Word8 -> ByteString -> Maybe Word8
step Maybe Word8
forall a. Maybe a
Nothing Maybe Word8 -> Maybe Word8
forall a. a -> a
id
where
step :: Maybe Word8 -> ByteString -> Maybe Word8
step Maybe Word8
mw8 ByteString
bs =
if (ByteString -> Bool
BS.null ByteString
bs)
then Maybe Word8
mw8
else case Maybe Word8
mw8 of
Maybe Word8
Nothing -> Word8 -> Maybe Word8
forall a. a -> Maybe a
Just (ByteString -> Word8
BS.minimum ByteString
bs)
Just Word8
w8 -> Word8 -> Maybe Word8
forall a. a -> Maybe a
Just (Word8 -> Word8 -> Word8
forall a. Ord a => a -> a -> a
min Word8
w8 (ByteString -> Word8
BS.minimum ByteString
bs))
{-# INLINABLE minimum #-}
elem :: Monad m => Word8 -> Producer ByteString m () -> m Bool
elem :: Word8 -> Producer ByteString m () -> m Bool
elem Word8
w8 = (ByteString -> Bool) -> Producer ByteString m () -> m Bool
forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Producer a m () -> m Bool
P.any (Word8 -> ByteString -> Bool
BS.elem Word8
w8)
{-# INLINABLE elem #-}
notElem :: Monad m => Word8 -> Producer ByteString m () -> m Bool
notElem :: Word8 -> Producer ByteString m () -> m Bool
notElem Word8
w8 = (ByteString -> Bool) -> Producer ByteString m () -> m Bool
forall (m :: * -> *) a.
Monad m =>
(a -> Bool) -> Producer a m () -> m Bool
P.all (Word8 -> ByteString -> Bool
BS.notElem Word8
w8)
{-# INLINABLE notElem #-}
find
:: Monad m
=> (Word8 -> Bool) -> Producer ByteString m () -> m (Maybe Word8)
find :: (Word8 -> Bool) -> Producer ByteString m () -> m (Maybe Word8)
find Word8 -> Bool
predicate Producer ByteString m ()
p = Producer ByteString m () -> m (Maybe Word8)
forall (m :: * -> *).
Monad m =>
Producer ByteString m () -> m (Maybe Word8)
head (Producer ByteString m ()
p Producer ByteString m ()
-> Proxy () ByteString () ByteString m ()
-> Producer ByteString m ()
forall (m :: * -> *) a' a b r c' c.
Functor m =>
Proxy a' a () b m r -> Proxy () b c' c m r -> Proxy a' a c' c m r
>-> (Word8 -> Bool) -> Proxy () ByteString () ByteString m ()
forall (m :: * -> *) r.
Monad m =>
(Word8 -> Bool) -> Pipe ByteString ByteString m r
filter Word8 -> Bool
predicate)
{-# INLINABLE find #-}
index
:: (Monad m, Integral n)
=> n -> Producer ByteString m () -> m (Maybe Word8)
index :: n -> Producer ByteString m () -> m (Maybe Word8)
index n
n Producer ByteString m ()
p = Producer ByteString m () -> m (Maybe Word8)
forall (m :: * -> *).
Monad m =>
Producer ByteString m () -> m (Maybe Word8)
head (n -> Producer ByteString m () -> Producer ByteString m ()
forall (m :: * -> *) n r.
(Monad m, Integral n) =>
n -> Producer ByteString m r -> Producer ByteString m r
drop n
n Producer ByteString m ()
p)
{-# INLINABLE index #-}
elemIndex
:: (Monad m, Num n) => Word8 -> Producer ByteString m () -> m (Maybe n)
elemIndex :: Word8 -> Producer ByteString m () -> m (Maybe n)
elemIndex Word8
w8 = (Word8 -> Bool) -> Producer ByteString m () -> m (Maybe n)
forall (m :: * -> *) n.
(Monad m, Num n) =>
(Word8 -> Bool) -> Producer ByteString m () -> m (Maybe n)
findIndex (Word8
w8 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
==)
{-# INLINABLE elemIndex #-}
findIndex
:: (Monad m, Num n)
=> (Word8 -> Bool) -> Producer ByteString m () -> m (Maybe n)
findIndex :: (Word8 -> Bool) -> Producer ByteString m () -> m (Maybe n)
findIndex Word8 -> Bool
predicate Producer ByteString m ()
p = Producer n m () -> m (Maybe n)
forall (m :: * -> *) a. Monad m => Producer a m () -> m (Maybe a)
P.head (Producer ByteString m ()
p Producer ByteString m ()
-> Proxy () ByteString () n m () -> Producer n m ()
forall (m :: * -> *) a' a b r c' c.
Functor m =>
Proxy a' a () b m r -> Proxy () b c' c m r -> Proxy a' a c' c m r
>-> (Word8 -> Bool) -> Proxy () ByteString () n m ()
forall (m :: * -> *) n r.
(Monad m, Num n) =>
(Word8 -> Bool) -> Pipe ByteString n m r
findIndices Word8 -> Bool
predicate)
{-# INLINABLE findIndex #-}
count :: (Monad m, Num n) => Word8 -> Producer ByteString m () -> m n
count :: Word8 -> Producer ByteString m () -> m n
count Word8
w8 Producer ByteString m ()
p = (n -> n -> n) -> n -> (n -> n) -> Producer n m () -> m n
forall (m :: * -> *) x a b.
Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b
P.fold n -> n -> n
forall a. Num a => a -> a -> a
(+) n
0 n -> n
forall a. a -> a
id (Producer ByteString m ()
p Producer ByteString m ()
-> Proxy () ByteString () n m () -> Producer n m ()
forall (m :: * -> *) a' a b r c' c.
Functor m =>
Proxy a' a () b m r -> Proxy () b c' c m r -> Proxy a' a c' c m r
>-> (ByteString -> n) -> Proxy () ByteString () n m ()
forall (m :: * -> *) a b r. Functor m => (a -> b) -> Pipe a b m r
P.map (Int -> n
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> n) -> (ByteString -> Int) -> ByteString -> n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> ByteString -> Int
BS.count Word8
w8))
{-# INLINABLE count #-}
nextByte
:: Monad m
=> Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
nextByte :: Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
nextByte = Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
forall (m :: * -> *) r.
Monad m =>
Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
go
where
go :: Producer ByteString m b
-> m (Either b (Word8, Producer ByteString m b))
go Producer ByteString m b
p = do
Either b (ByteString, Producer ByteString m b)
x <- Producer ByteString m b
-> m (Either b (ByteString, Producer ByteString m b))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m b
p
case Either b (ByteString, Producer ByteString m b)
x of
Left b
r -> Either b (Word8, Producer ByteString m b)
-> m (Either b (Word8, Producer ByteString m b))
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> Either b (Word8, Producer ByteString m b)
forall a b. a -> Either a b
Left b
r)
Right (ByteString
bs, Producer ByteString m b
p') -> case (ByteString -> Maybe (Word8, ByteString)
BS.uncons ByteString
bs) of
Maybe (Word8, ByteString)
Nothing -> Producer ByteString m b
-> m (Either b (Word8, Producer ByteString m b))
go Producer ByteString m b
p'
Just (Word8
w8, ByteString
bs') -> Either b (Word8, Producer ByteString m b)
-> m (Either b (Word8, Producer ByteString m b))
forall (m :: * -> *) a. Monad m => a -> m a
return ((Word8, Producer ByteString m b)
-> Either b (Word8, Producer ByteString m b)
forall a b. b -> Either a b
Right (Word8
w8, ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs' Proxy X () () ByteString m ()
-> Producer ByteString m b -> Producer ByteString m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m b
p'))
{-# INLINABLE nextByte #-}
drawByte :: Monad m => Parser ByteString m (Maybe Word8)
drawByte :: Parser ByteString m (Maybe Word8)
drawByte = do
Maybe ByteString
x <- StateT (Producer ByteString m x) m (Maybe ByteString)
forall (m :: * -> *) a. Monad m => Parser a m (Maybe a)
PP.draw
case Maybe ByteString
x of
Maybe ByteString
Nothing -> Maybe Word8 -> StateT (Producer ByteString m x) m (Maybe Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Word8
forall a. Maybe a
Nothing
Just ByteString
bs -> case (ByteString -> Maybe (Word8, ByteString)
BS.uncons ByteString
bs) of
Maybe (Word8, ByteString)
Nothing -> StateT (Producer ByteString m x) m (Maybe Word8)
forall (m :: * -> *). Monad m => Parser ByteString m (Maybe Word8)
drawByte
Just (Word8
w8, ByteString
bs') -> do
ByteString -> Parser ByteString m ()
forall (m :: * -> *) a. Monad m => a -> Parser a m ()
PP.unDraw ByteString
bs'
Maybe Word8 -> StateT (Producer ByteString m x) m (Maybe Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return (Word8 -> Maybe Word8
forall a. a -> Maybe a
Just Word8
w8)
{-# INLINABLE drawByte #-}
unDrawByte :: Monad m => Word8 -> Parser ByteString m ()
unDrawByte :: Word8 -> Parser ByteString m ()
unDrawByte Word8
w8 = (Proxy X () () ByteString m x -> Proxy X () () ByteString m x)
-> StateT (Proxy X () () ByteString m x) m ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Word8 -> ByteString
BS.singleton Word8
w8) Proxy X () () ByteString m ()
-> Proxy X () () ByteString m x -> Proxy X () () ByteString m x
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>)
{-# INLINABLE unDrawByte #-}
peekByte :: Monad m => Parser ByteString m (Maybe Word8)
peekByte :: Parser ByteString m (Maybe Word8)
peekByte = do
Maybe Word8
x <- StateT (Producer ByteString m x) m (Maybe Word8)
forall (m :: * -> *). Monad m => Parser ByteString m (Maybe Word8)
drawByte
case Maybe Word8
x of
Maybe Word8
Nothing -> () -> StateT (Producer ByteString m x) m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just Word8
w8 -> Word8 -> Parser ByteString m ()
forall (m :: * -> *). Monad m => Word8 -> Parser ByteString m ()
unDrawByte Word8
w8
Maybe Word8 -> StateT (Producer ByteString m x) m (Maybe Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Word8
x
{-# INLINABLE peekByte #-}
isEndOfBytes :: Monad m => Parser ByteString m Bool
isEndOfBytes :: Parser ByteString m Bool
isEndOfBytes = do
Maybe Word8
x <- StateT (Producer ByteString m x) m (Maybe Word8)
forall (m :: * -> *). Monad m => Parser ByteString m (Maybe Word8)
peekByte
Bool -> StateT (Producer ByteString m x) m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (case Maybe Word8
x of
Maybe Word8
Nothing -> Bool
True
Just Word8
_ -> Bool
False )
{-# INLINABLE isEndOfBytes #-}
type Lens' a b = forall f . Functor f => (b -> f b) -> (a -> f a)
splitAt
:: (Monad m, Integral n)
=> n
-> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
splitAt :: n
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
splitAt n
n0 Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k Producer ByteString m x
p0 = (Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k (n
-> Producer ByteString m x
-> Producer ByteString m (Producer ByteString m x)
forall t (m :: * -> *) b x' x.
(Monad m, Integral t) =>
t
-> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go n
n0 Producer ByteString m x
p0))
where
go :: t
-> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go t
n Producer ByteString m b
p =
if (t
n t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
0)
then Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return Producer ByteString m b
p
else do
Either b (ByteString, Producer ByteString m b)
x <- m (Either b (ByteString, Producer ByteString m b))
-> Proxy
x'
x
()
ByteString
m
(Either b (ByteString, Producer ByteString m b))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Producer ByteString m b
-> m (Either b (ByteString, Producer ByteString m b))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m b
p)
case Either b (ByteString, Producer ByteString m b)
x of
Left b
r -> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> Producer ByteString m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
r)
Right (ByteString
bs, Producer ByteString m b
p') -> do
let len :: t
len = Int -> t
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ByteString -> Int
BS.length ByteString
bs)
if (t
len t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
n)
then do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs
t
-> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go (t
n t -> t -> t
forall a. Num a => a -> a -> a
- t
len) Producer ByteString m b
p'
else do
let (ByteString
prefix, ByteString
suffix) =
Int -> ByteString -> (ByteString, ByteString)
BS.splitAt (t -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral t
n) ByteString
bs
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
prefix
Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
suffix Proxy X () () ByteString m ()
-> Producer ByteString m b -> Producer ByteString m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m b
p')
{-# INLINABLE splitAt #-}
span
:: Monad m
=> (Word8 -> Bool)
-> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
span :: (Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
span Word8 -> Bool
predicate Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k Producer ByteString m x
p0 = (Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k (Producer ByteString m x
-> Producer ByteString m (Producer ByteString m x)
forall (m :: * -> *) b x' x.
Monad m =>
Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go Producer ByteString m x
p0))
where
go :: Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go Producer ByteString m b
p = do
Either b (ByteString, Producer ByteString m b)
x <- m (Either b (ByteString, Producer ByteString m b))
-> Proxy
x'
x
()
ByteString
m
(Either b (ByteString, Producer ByteString m b))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Producer ByteString m b
-> m (Either b (ByteString, Producer ByteString m b))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m b
p)
case Either b (ByteString, Producer ByteString m b)
x of
Left b
r -> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> Producer ByteString m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
r)
Right (ByteString
bs, Producer ByteString m b
p') -> do
let (ByteString
prefix, ByteString
suffix) = (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
BS.span Word8 -> Bool
predicate ByteString
bs
if (ByteString -> Bool
BS.null ByteString
suffix)
then do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs
Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go Producer ByteString m b
p'
else do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
prefix
Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
suffix Proxy X () () ByteString m ()
-> Producer ByteString m b -> Producer ByteString m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m b
p')
{-# INLINABLE span #-}
break
:: Monad m
=> (Word8 -> Bool)
-> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
break :: (Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
break Word8 -> Bool
predicate = (Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
span (Bool -> Bool
not (Bool -> Bool) -> (Word8 -> Bool) -> Word8 -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Bool
predicate)
{-# INLINABLE break #-}
breakOn
:: Monad m
=> ByteString
-> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
breakOn :: ByteString
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
breakOn ByteString
needle Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k Producer ByteString m x
p0 =
(Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k (ByteString
-> Producer ByteString m x
-> Producer ByteString m (Producer ByteString m x)
forall (m :: * -> *) b x' x.
Monad m =>
ByteString
-> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go ByteString
forall a. Monoid a => a
mempty Producer ByteString m x
p0))
where
len0 :: Int
len0 = ByteString -> Int
BS.length ByteString
needle
go :: ByteString
-> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go ByteString
leftovers Producer ByteString m b
p =
if ByteString -> Int
BS.length ByteString
leftovers Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
len0
then do
Either b (ByteString, Producer ByteString m b)
x <- m (Either b (ByteString, Producer ByteString m b))
-> Proxy
x'
x
()
ByteString
m
(Either b (ByteString, Producer ByteString m b))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Producer ByteString m b
-> m (Either b (ByteString, Producer ByteString m b))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m b
p)
case Either b (ByteString, Producer ByteString m b)
x of
Left b
r -> do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
leftovers
Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> Producer ByteString m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
r)
Right (ByteString
bytes, Producer ByteString m b
p') -> do
ByteString
-> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go (ByteString
leftovers ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
bytes) Producer ByteString m b
p'
else do
let (ByteString
prefix, ByteString
suffix) = ByteString -> ByteString -> (ByteString, ByteString)
Data.ByteString.Search.breakOn ByteString
needle ByteString
leftovers
if ByteString -> Bool
BS.null ByteString
suffix
then do
let len :: Int
len = ByteString -> Int
BS.length ByteString
leftovers
let (ByteString
output, ByteString
leftovers') =
Int -> ByteString -> (ByteString, ByteString)
BS.splitAt (Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
len0) ByteString
leftovers
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
output
ByteString
-> Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
go ByteString
leftovers' Producer ByteString m b
p
else do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
prefix
Producer ByteString m b
-> Proxy x' x () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
suffix Proxy X () () ByteString m ()
-> Producer ByteString m b -> Producer ByteString m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m b
p)
{-# INLINABLE breakOn #-}
groupBy
:: Monad m
=> (Word8 -> Word8 -> Bool)
-> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
groupBy :: (Word8 -> Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
groupBy Word8 -> Word8 -> Bool
equals Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k Producer ByteString m x
p0 = (Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k (Producer ByteString m x
-> Producer ByteString m (Producer ByteString m x)
forall (m :: * -> *) b.
Monad m =>
Producer ByteString m b
-> Proxy X () () ByteString m (Producer ByteString m b)
_groupBy Producer ByteString m x
p0))
where
_groupBy :: Producer ByteString m b
-> Proxy X () () ByteString m (Producer ByteString m b)
_groupBy Producer ByteString m b
p = do
Either b (ByteString, Producer ByteString m b)
x <- m (Either b (ByteString, Producer ByteString m b))
-> Proxy
X
()
()
ByteString
m
(Either b (ByteString, Producer ByteString m b))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Producer ByteString m b
-> m (Either b (ByteString, Producer ByteString m b))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m b
p)
case Either b (ByteString, Producer ByteString m b)
x of
Left b
r -> Producer ByteString m b
-> Proxy X () () ByteString m (Producer ByteString m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b -> Producer ByteString m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
r)
Right (ByteString
bs, Producer ByteString m b
p') -> case (ByteString -> Maybe (Word8, ByteString)
BS.uncons ByteString
bs) of
Maybe (Word8, ByteString)
Nothing -> Producer ByteString m b
-> Proxy X () () ByteString m (Producer ByteString m b)
_groupBy Producer ByteString m b
p'
Just (Word8
w8, ByteString
_) -> (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs Proxy X () () ByteString m ()
-> Producer ByteString m b -> Producer ByteString m b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m b
p')Producer ByteString m b
-> ((Proxy X () () ByteString m (Producer ByteString m b)
-> Constant
(Proxy X () () ByteString m (Producer ByteString m b))
(Proxy X () () ByteString m (Producer ByteString m b)))
-> Producer ByteString m b
-> Constant
(Proxy X () () ByteString m (Producer ByteString m b))
(Producer ByteString m b))
-> Proxy X () () ByteString m (Producer ByteString m b)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(Word8 -> Bool)
-> Lens'
(Producer ByteString m b)
(Proxy X () () ByteString m (Producer ByteString m b))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
span (Word8 -> Word8 -> Bool
equals Word8
w8)
{-# INLINABLE groupBy #-}
group
:: Monad m
=> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
group :: Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
group = (Word8 -> Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
groupBy Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINABLE group #-}
word
:: Monad m
=> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
word :: Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
word Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k Producer ByteString m x
p0 = (Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer ByteString m (Producer ByteString m x)
-> Producer ByteString m x
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Producer ByteString m (Producer ByteString m x)
-> f (Producer ByteString m (Producer ByteString m x))
k (Producer ByteString m x
-> Producer ByteString m (Producer ByteString m x)
forall (m :: * -> *) b.
Monad m =>
Producer ByteString m b
-> Proxy X () () ByteString m (Producer ByteString m b)
to Producer ByteString m x
p0))
where
to :: Producer ByteString m x
-> Proxy X () () ByteString m (Producer ByteString m x)
to Producer ByteString m x
p = do
Producer ByteString m x
p' <- Producer ByteString m x
pProducer ByteString m x
-> ((Proxy X () () ByteString m (Producer ByteString m x)
-> Constant
(Proxy X () () ByteString m (Producer ByteString m x))
(Proxy X () () ByteString m (Producer ByteString m x)))
-> Producer ByteString m x
-> Constant
(Proxy X () () ByteString m (Producer ByteString m x))
(Producer ByteString m x))
-> Proxy X () () ByteString m (Producer ByteString m x)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Proxy X () () ByteString m (Producer ByteString m x))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
span Word8 -> Bool
isSpaceWord8
Producer ByteString m x
p'Producer ByteString m x
-> ((Proxy X () () ByteString m (Producer ByteString m x)
-> Constant
(Proxy X () () ByteString m (Producer ByteString m x))
(Proxy X () () ByteString m (Producer ByteString m x)))
-> Producer ByteString m x
-> Constant
(Proxy X () () ByteString m (Producer ByteString m x))
(Producer ByteString m x))
-> Proxy X () () ByteString m (Producer ByteString m x)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Proxy X () () ByteString m (Producer ByteString m x))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
break Word8 -> Bool
isSpaceWord8
{-# INLINABLE word #-}
nl :: Word8
nl :: Word8
nl = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Char -> Int
ord Char
'\n')
line
:: Monad m
=> Lens' (Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
line :: Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
line = (Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
break (Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
== Word8
nl)
{-# INLINABLE line #-}
drop
:: (Monad m, Integral n)
=> n -> Producer ByteString m r -> Producer ByteString m r
drop :: n -> Producer ByteString m r -> Producer ByteString m r
drop n
n Producer ByteString m r
p = do
Producer ByteString m r
p' <- m (Producer ByteString m r)
-> Proxy X () () ByteString m (Producer ByteString m r)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Producer ByteString m r)
-> Proxy X () () ByteString m (Producer ByteString m r))
-> m (Producer ByteString m r)
-> Proxy X () () ByteString m (Producer ByteString m r)
forall a b. (a -> b) -> a -> b
$ Effect m (Producer ByteString m r) -> m (Producer ByteString m r)
forall (m :: * -> *) r. Monad m => Effect m r -> m r
runEffect (Proxy X () () ByteString m (Producer ByteString m r)
-> (ByteString -> Proxy X () () X m ())
-> Effect m (Producer ByteString m r)
forall (m :: * -> *) x' x b' b a' c' c.
Functor m =>
Proxy x' x b' b m a'
-> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a'
for (Producer ByteString m r
p Producer ByteString m r
-> ((Proxy X () () ByteString m (Producer ByteString m r)
-> Constant
(Proxy X () () ByteString m (Producer ByteString m r))
(Proxy X () () ByteString m (Producer ByteString m r)))
-> Producer ByteString m r
-> Constant
(Proxy X () () ByteString m (Producer ByteString m r))
(Producer ByteString m r))
-> Proxy X () () ByteString m (Producer ByteString m r)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^. n
-> Lens'
(Producer ByteString m r)
(Proxy X () () ByteString m (Producer ByteString m r))
forall (m :: * -> *) n x.
(Monad m, Integral n) =>
n
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
splitAt n
n) ByteString -> Proxy X () () X m ()
forall (m :: * -> *) a. Monad m => a -> m ()
discard)
Producer ByteString m r
p'
{-# INLINABLE drop #-}
dropWhile
:: Monad m
=> (Word8 -> Bool) -> Producer ByteString m r -> Producer ByteString m r
dropWhile :: (Word8 -> Bool)
-> Producer ByteString m r -> Producer ByteString m r
dropWhile Word8 -> Bool
predicate Producer ByteString m r
p = do
Producer ByteString m r
p' <- m (Producer ByteString m r)
-> Proxy X () () ByteString m (Producer ByteString m r)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m (Producer ByteString m r)
-> Proxy X () () ByteString m (Producer ByteString m r))
-> m (Producer ByteString m r)
-> Proxy X () () ByteString m (Producer ByteString m r)
forall a b. (a -> b) -> a -> b
$ Effect m (Producer ByteString m r) -> m (Producer ByteString m r)
forall (m :: * -> *) r. Monad m => Effect m r -> m r
runEffect (Proxy X () () ByteString m (Producer ByteString m r)
-> (ByteString -> Proxy X () () X m ())
-> Effect m (Producer ByteString m r)
forall (m :: * -> *) x' x b' b a' c' c.
Functor m =>
Proxy x' x b' b m a'
-> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a'
for (Producer ByteString m r
p Producer ByteString m r
-> ((Proxy X () () ByteString m (Producer ByteString m r)
-> Constant
(Proxy X () () ByteString m (Producer ByteString m r))
(Proxy X () () ByteString m (Producer ByteString m r)))
-> Producer ByteString m r
-> Constant
(Proxy X () () ByteString m (Producer ByteString m r))
(Producer ByteString m r))
-> Proxy X () () ByteString m (Producer ByteString m r)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^. (Word8 -> Bool)
-> Lens'
(Producer ByteString m r)
(Proxy X () () ByteString m (Producer ByteString m r))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
span Word8 -> Bool
predicate) ByteString -> Proxy X () () X m ()
forall (m :: * -> *) a. Monad m => a -> m ()
discard)
Producer ByteString m r
p'
{-# INLINABLE dropWhile #-}
intersperse
:: Monad m => Word8 -> Producer ByteString m r -> Producer ByteString m r
intersperse :: Word8 -> Producer ByteString m r -> Producer ByteString m r
intersperse Word8
w8 = Producer ByteString m r -> Producer ByteString m r
forall (m :: * -> *) b x' x.
Monad m =>
Producer ByteString m b -> Proxy x' x () ByteString m b
go0
where
go0 :: Producer ByteString m b -> Proxy x' x () ByteString m b
go0 Producer ByteString m b
p = do
Either b (ByteString, Producer ByteString m b)
x <- m (Either b (ByteString, Producer ByteString m b))
-> Proxy
x'
x
()
ByteString
m
(Either b (ByteString, Producer ByteString m b))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Producer ByteString m b
-> m (Either b (ByteString, Producer ByteString m b))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m b
p)
case Either b (ByteString, Producer ByteString m b)
x of
Left b
r -> b -> Proxy x' x () ByteString m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
r
Right (ByteString
bs, Producer ByteString m b
p') -> do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Word8 -> ByteString -> ByteString
BS.intersperse Word8
w8 ByteString
bs)
Producer ByteString m b -> Proxy x' x () ByteString m b
forall (m :: * -> *) b x' x.
Monad m =>
Producer ByteString m b -> Proxy x' x () ByteString m b
go1 Producer ByteString m b
p'
go1 :: Producer ByteString m b -> Proxy x' x () ByteString m b
go1 Producer ByteString m b
p = do
Either b (ByteString, Producer ByteString m b)
x <- m (Either b (ByteString, Producer ByteString m b))
-> Proxy
x'
x
()
ByteString
m
(Either b (ByteString, Producer ByteString m b))
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (Producer ByteString m b
-> m (Either b (ByteString, Producer ByteString m b))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m b
p)
case Either b (ByteString, Producer ByteString m b)
x of
Left b
r -> b -> Proxy x' x () ByteString m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
r
Right (ByteString
bs, Producer ByteString m b
p') -> do
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Word8 -> ByteString
BS.singleton Word8
w8)
ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Word8 -> ByteString -> ByteString
BS.intersperse Word8
w8 ByteString
bs)
Producer ByteString m b -> Proxy x' x () ByteString m b
go1 Producer ByteString m b
p'
{-# INLINABLE intersperse #-}
pack :: Monad m => Lens' (Producer Word8 m x) (Producer ByteString m x)
pack :: Lens' (Producer Word8 m x) (Producer ByteString m x)
pack Producer ByteString m x -> f (Producer ByteString m x)
k Producer Word8 m x
p = (Producer ByteString m x -> Producer Word8 m x)
-> f (Producer ByteString m x) -> f (Producer Word8 m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer ByteString m x -> Producer Word8 m x
forall (m :: * -> *) x.
Monad m =>
Producer ByteString m x -> Producer Word8 m x
_unpack (Producer ByteString m x -> f (Producer ByteString m x)
k (Producer Word8 m x -> Producer ByteString m x
forall (m :: * -> *) x.
Monad m =>
Producer Word8 m x -> Producer ByteString m x
_pack Producer Word8 m x
p))
{-# INLINABLE pack #-}
unpack :: Monad m => Lens' (Producer ByteString m x) (Producer Word8 m x)
unpack :: Lens' (Producer ByteString m x) (Producer Word8 m x)
unpack Producer Word8 m x -> f (Producer Word8 m x)
k Producer ByteString m x
p = (Producer Word8 m x -> Producer ByteString m x)
-> f (Producer Word8 m x) -> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer Word8 m x -> Producer ByteString m x
forall (m :: * -> *) x.
Monad m =>
Producer Word8 m x -> Producer ByteString m x
_pack (Producer Word8 m x -> f (Producer Word8 m x)
k (Producer ByteString m x -> Producer Word8 m x
forall (m :: * -> *) x.
Monad m =>
Producer ByteString m x -> Producer Word8 m x
_unpack Producer ByteString m x
p))
{-# INLINABLE unpack #-}
_pack :: Monad m => Producer Word8 m x -> Producer ByteString m x
_pack :: Producer Word8 m x -> Producer ByteString m x
_pack Producer Word8 m x
p = (([Word8] -> [Word8]) -> Word8 -> [Word8] -> [Word8])
-> ([Word8] -> [Word8])
-> (([Word8] -> [Word8]) -> ByteString)
-> FreeT (Producer Word8 m) m x
-> Producer ByteString m x
forall (m :: * -> *) x a b r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> FreeT (Producer a m) m r -> Producer b m r
PG.folds ([Word8] -> [Word8]) -> Word8 -> [Word8] -> [Word8]
forall a c. ([a] -> c) -> a -> [a] -> c
step [Word8] -> [Word8]
forall a. a -> a
id ([Word8] -> [Word8]) -> ByteString
forall a. ([a] -> [Word8]) -> ByteString
done (Producer Word8 m x
pProducer Word8 m x
-> ((FreeT (Producer Word8 m) m x
-> Constant
(FreeT (Producer Word8 m) m x) (FreeT (Producer Word8 m) m x))
-> Producer Word8 m x
-> Constant (FreeT (Producer Word8 m) m x) (Producer Word8 m x))
-> FreeT (Producer Word8 m) m x
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.Int
-> Lens
(Producer Word8 m x)
(Producer Word8 m x)
(FreeT (Producer Word8 m) m x)
(FreeT (Producer Word8 m) m x)
forall (m :: * -> *) a' x a.
Monad m =>
Int
-> Lens
(Producer a' m x)
(Producer a m x)
(FreeT (Producer a' m) m x)
(FreeT (Producer a m) m x)
PG.chunksOf Int
defaultChunkSize)
where
step :: ([a] -> c) -> a -> [a] -> c
step [a] -> c
diffAs a
w8 = [a] -> c
diffAs ([a] -> c) -> ([a] -> [a]) -> [a] -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
w8a -> [a] -> [a]
forall a. a -> [a] -> [a]
:)
done :: ([a] -> [Word8]) -> ByteString
done [a] -> [Word8]
diffAs = [Word8] -> ByteString
BS.pack ([a] -> [Word8]
diffAs [])
{-# INLINABLE _pack #-}
_unpack :: Monad m => Producer ByteString m x -> Producer Word8 m x
_unpack :: Producer ByteString m x -> Producer Word8 m x
_unpack Producer ByteString m x
p = Producer ByteString m x
-> (ByteString -> Proxy X () () Word8 m ()) -> Producer Word8 m x
forall (m :: * -> *) x' x b' b a' c' c.
Functor m =>
Proxy x' x b' b m a'
-> (b -> Proxy x' x c' c m b') -> Proxy x' x c' c m a'
for Producer ByteString m x
p ([Word8] -> Proxy X () () Word8 m ()
forall (m :: * -> *) (f :: * -> *) a x' x.
(Functor m, Foldable f) =>
f a -> Proxy x' x () a m ()
each ([Word8] -> Proxy X () () Word8 m ())
-> (ByteString -> [Word8])
-> ByteString
-> Proxy X () () Word8 m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [Word8]
BS.unpack)
{-# INLINABLE _unpack #-}
chunksOf'
:: (Monad m, Integral n)
=> n -> Producer ByteString m r -> Producer ByteString m r
chunksOf' :: n -> Producer ByteString m r -> Producer ByteString m r
chunksOf' n
n Producer ByteString m r
p =
(([ByteString] -> [ByteString])
-> ByteString -> [ByteString] -> [ByteString])
-> ([ByteString] -> [ByteString])
-> (([ByteString] -> [ByteString]) -> ByteString)
-> FreeT (Producer ByteString m) m r
-> Producer ByteString m r
forall (m :: * -> *) x a b r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> FreeT (Producer a m) m r -> Producer b m r
PG.folds
(\[ByteString] -> [ByteString]
diffBs ByteString
bs -> [ByteString] -> [ByteString]
diffBs ([ByteString] -> [ByteString])
-> ([ByteString] -> [ByteString]) -> [ByteString] -> [ByteString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString
bsByteString -> [ByteString] -> [ByteString]
forall a. a -> [a] -> [a]
:))
[ByteString] -> [ByteString]
forall a. a -> a
id
(\[ByteString] -> [ByteString]
diffBs -> [ByteString] -> ByteString
BS.concat ([ByteString] -> [ByteString]
diffBs []))
(Producer ByteString m r
p Producer ByteString m r
-> ((FreeT (Producer ByteString m) m r
-> Constant
(FreeT (Producer ByteString m) m r)
(FreeT (Producer ByteString m) m r))
-> Producer ByteString m r
-> Constant
(FreeT (Producer ByteString m) m r) (Producer ByteString m r))
-> FreeT (Producer ByteString m) m r
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^. n
-> Lens'
(Producer ByteString m r) (FreeT (Producer ByteString m) m r)
forall (m :: * -> *) n x.
(Monad m, Integral n) =>
n
-> Lens'
(Producer ByteString m x) (FreeT (Producer ByteString m) m x)
chunksOf n
n)
{-# INLINABLE chunksOf' #-}
chunksOf
:: (Monad m, Integral n)
=> n -> Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
chunksOf :: n
-> Lens'
(Producer ByteString m x) (FreeT (Producer ByteString m) m x)
chunksOf n
n FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k Producer ByteString m x
p0 = (FreeT (Producer ByteString m) m x -> Producer ByteString m x)
-> f (FreeT (Producer ByteString m) m x)
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) a x.
Monad m =>
FreeT (Producer a m) m x -> Producer a m x
concats (FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k (Producer ByteString m x -> FreeT (Producer ByteString m) m x
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
go Producer ByteString m x
p0))
where
go :: Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
go Producer ByteString m a
p = m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall a b. (a -> b) -> a -> b
$ do
Either a (ByteString, Producer ByteString m a)
x <- Producer ByteString m a
-> m (Either a (ByteString, Producer ByteString m a))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m a
p
FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)))
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall a b. (a -> b) -> a -> b
$ case Either a (ByteString, Producer ByteString m a)
x of
Left a
r -> a
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure a
r
Right (ByteString
bs, Producer ByteString m a
p') -> Proxy X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. f b -> FreeF f a b
PG.Free (Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ do
Producer ByteString m a
p'' <- (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs Proxy X () () ByteString m ()
-> Producer ByteString m a -> Producer ByteString m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m a
p')Producer ByteString m a
-> ((Producer ByteString m (Producer ByteString m a)
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m (Producer ByteString m a)))
-> Producer ByteString m a
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m a))
-> Producer ByteString m (Producer ByteString m a)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.n
-> Lens'
(Producer ByteString m a)
(Producer ByteString m (Producer ByteString m a))
forall (m :: * -> *) n x.
(Monad m, Integral n) =>
n
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
splitAt n
n
FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
go Producer ByteString m a
p'')
{-# INLINABLE chunksOf #-}
splitsWith
:: Monad m
=> (Word8 -> Bool)
-> Producer ByteString m x -> FreeT (Producer ByteString m) m x
splitsWith :: (Word8 -> Bool)
-> Producer ByteString m x -> FreeT (Producer ByteString m) m x
splitsWith Word8 -> Bool
predicate Producer ByteString m x
p0 = m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
-> FreeT (Producer ByteString m) m x
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (Producer ByteString m x
-> m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go0 Producer ByteString m x
p0)
where
go0 :: Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go0 Producer ByteString m a
p = do
Either a (ByteString, Producer ByteString m a)
x <- Producer ByteString m a
-> m (Either a (ByteString, Producer ByteString m a))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m a
p
case Either a (ByteString, Producer ByteString m a)
x of
Left a
r -> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (a
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure a
r)
Right (ByteString
bs, Producer ByteString m a
p') ->
if (ByteString -> Bool
BS.null ByteString
bs)
then Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go0 Producer ByteString m a
p'
else Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go1 (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs Proxy X () () ByteString m ()
-> Producer ByteString m a -> Producer ByteString m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m a
p')
go1 :: Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go1 Producer ByteString m a
p = FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)))
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall a b. (a -> b) -> a -> b
$ Proxy X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. f b -> FreeF f a b
PG.Free (Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ do
Producer ByteString m a
p' <- Producer ByteString m a
pProducer ByteString m a
-> ((Producer ByteString m (Producer ByteString m a)
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m (Producer ByteString m a)))
-> Producer ByteString m a
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m a))
-> Producer ByteString m (Producer ByteString m a)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(Word8 -> Bool)
-> Lens'
(Producer ByteString m a)
(Producer ByteString m (Producer ByteString m a))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
break Word8 -> Bool
predicate
FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall a b. (a -> b) -> a -> b
$ do
Either a (Word8, Producer ByteString m a)
x <- Producer ByteString m a
-> m (Either a (Word8, Producer ByteString m a))
forall (m :: * -> *) r.
Monad m =>
Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
nextByte Producer ByteString m a
p'
case Either a (Word8, Producer ByteString m a)
x of
Left a
r -> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (a
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure a
r)
Right (Word8
_, Producer ByteString m a
p'') -> Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go1 Producer ByteString m a
p''
{-# INLINABLE splitsWith #-}
splits
:: Monad m
=> Word8
-> Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
splits :: Word8
-> Lens'
(Producer ByteString m x) (FreeT (Producer ByteString m) m x)
splits Word8
w8 FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k Producer ByteString m x
p =
(FreeT (Producer ByteString m) m x -> Producer ByteString m x)
-> f (FreeT (Producer ByteString m) m x)
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Producer ByteString m ()
-> FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) a x.
Monad m =>
Producer a m () -> FreeT (Producer a m) m x -> Producer a m x
PG.intercalates (ByteString -> Producer ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Word8 -> ByteString
BS.singleton Word8
w8))) (FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k ((Word8 -> Bool)
-> Producer ByteString m x -> FreeT (Producer ByteString m) m x
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Producer ByteString m x -> FreeT (Producer ByteString m) m x
splitsWith (Word8
w8 Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
==) Producer ByteString m x
p))
{-# INLINABLE splits #-}
splitOn
:: Monad m
=> ByteString
-> Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
splitOn :: ByteString
-> Lens'
(Producer ByteString m x) (FreeT (Producer ByteString m) m x)
splitOn ByteString
needle FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k Producer ByteString m x
p0 =
(FreeT (Producer ByteString m) m x -> Producer ByteString m x)
-> f (FreeT (Producer ByteString m) m x)
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
(Producer ByteString m ()
-> FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) a x.
Monad m =>
Producer a m () -> FreeT (Producer a m) m x -> Producer a m x
PG.intercalates (ByteString -> Producer ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
needle))
(FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k (Producer ByteString m x -> FreeT (Producer ByteString m) m x
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
go Producer ByteString m x
p0))
where
len0 :: Int
len0 = ByteString -> Int
BS.length ByteString
needle
go :: Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
go Producer ByteString m a
p = m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall a b. (a -> b) -> a -> b
$ do
Either a (ByteString, Producer ByteString m a)
x <- Producer ByteString m a
-> m (Either a (ByteString, Producer ByteString m a))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m a
p
FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)))
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall a b. (a -> b) -> a -> b
$ case Either a (ByteString, Producer ByteString m a)
x of
Left a
r -> a
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure a
r
Right (ByteString
bs, Producer ByteString m a
p') -> Proxy X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. f b -> FreeF f a b
PG.Free (Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ do
Producer ByteString m a
p'' <- (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs Proxy X () () ByteString m ()
-> Producer ByteString m a -> Producer ByteString m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m a
p')Producer ByteString m a
-> ((Producer ByteString m (Producer ByteString m a)
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m (Producer ByteString m a)))
-> Producer ByteString m a
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m a))
-> Producer ByteString m (Producer ByteString m a)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(ByteString
-> Lens'
(Producer ByteString m a)
(Producer ByteString m (Producer ByteString m a))
forall (m :: * -> *) x.
Monad m =>
ByteString
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
breakOn ByteString
needle)
FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
go (Int -> Producer ByteString m a -> Producer ByteString m a
forall (m :: * -> *) n r.
(Monad m, Integral n) =>
n -> Producer ByteString m r -> Producer ByteString m r
drop Int
len0 Producer ByteString m a
p''))
{-# INLINABLE splitOn #-}
groupsBy
:: Monad m
=> (Word8 -> Word8 -> Bool)
-> Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
groupsBy :: (Word8 -> Word8 -> Bool)
-> Lens'
(Producer ByteString m x) (FreeT (Producer ByteString m) m x)
groupsBy Word8 -> Word8 -> Bool
equals FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k Producer ByteString m x
p0 = (FreeT (Producer ByteString m) m x -> Producer ByteString m x)
-> f (FreeT (Producer ByteString m) m x)
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) a x.
Monad m =>
FreeT (Producer a m) m x -> Producer a m x
concats (FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k (Producer ByteString m x -> FreeT (Producer ByteString m) m x
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
_groupsBy Producer ByteString m x
p0))
where
_groupsBy :: Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
_groupsBy Producer ByteString m a
p0' = m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go Producer ByteString m a
p0')
where
go :: Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go Producer ByteString m a
p = do
Either a (ByteString, Producer ByteString m a)
x <- Producer ByteString m a
-> m (Either a (ByteString, Producer ByteString m a))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m a
p
case Either a (ByteString, Producer ByteString m a)
x of
Left a
r -> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (a
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure a
r)
Right (ByteString
bs, Producer ByteString m a
p') -> case (ByteString -> Maybe (Word8, ByteString)
BS.uncons ByteString
bs) of
Maybe (Word8, ByteString)
Nothing -> Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go Producer ByteString m a
p'
Just (Word8
w8, ByteString
_) -> do
FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)))
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall a b. (a -> b) -> a -> b
$ Proxy X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. f b -> FreeF f a b
PG.Free (Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ do
Producer ByteString m a
p'' <- (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs Proxy X () () ByteString m ()
-> Producer ByteString m a -> Producer ByteString m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m a
p')Producer ByteString m a
-> ((Producer ByteString m (Producer ByteString m a)
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m (Producer ByteString m a)))
-> Producer ByteString m a
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m a))
-> Producer ByteString m (Producer ByteString m a)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(Word8 -> Bool)
-> Lens'
(Producer ByteString m a)
(Producer ByteString m (Producer ByteString m a))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
span (Word8 -> Word8 -> Bool
equals Word8
w8)
FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go Producer ByteString m a
p'')
{-# INLINABLE groupsBy #-}
groups
:: Monad m
=> Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
groups :: Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
groups = (Word8 -> Word8 -> Bool)
-> Lens'
(Producer ByteString m x) (FreeT (Producer ByteString m) m x)
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Word8 -> Bool)
-> Lens'
(Producer ByteString m x) (FreeT (Producer ByteString m) m x)
groupsBy Word8 -> Word8 -> Bool
forall a. Eq a => a -> a -> Bool
(==)
{-# INLINABLE groups #-}
lines
:: Monad m
=> Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
lines :: Lens' (Producer ByteString m x) (FreeT (Producer ByteString m) m x)
lines FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k Producer ByteString m x
p = (FreeT (Producer ByteString m) m x -> Producer ByteString m x)
-> f (FreeT (Producer ByteString m) m x)
-> f (Producer ByteString m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) x.
Monad m =>
FreeT (Producer ByteString m) m x -> Producer ByteString m x
_unlines (FreeT (Producer ByteString m) m x
-> f (FreeT (Producer ByteString m) m x)
k (Producer ByteString m x -> FreeT (Producer ByteString m) m x
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
_lines Producer ByteString m x
p))
{-# INLINABLE lines #-}
unlines
:: Monad m
=> Lens' (FreeT (Producer ByteString m) m x) (Producer ByteString m x)
unlines :: Lens' (FreeT (Producer ByteString m) m x) (Producer ByteString m x)
unlines Producer ByteString m x -> f (Producer ByteString m x)
k FreeT (Producer ByteString m) m x
p = (Producer ByteString m x -> FreeT (Producer ByteString m) m x)
-> f (Producer ByteString m x)
-> f (FreeT (Producer ByteString m) m x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Producer ByteString m x -> FreeT (Producer ByteString m) m x
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
_lines (Producer ByteString m x -> f (Producer ByteString m x)
k (FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) x.
Monad m =>
FreeT (Producer ByteString m) m x -> Producer ByteString m x
_unlines FreeT (Producer ByteString m) m x
p))
{-# INLINABLE unlines #-}
_lines
:: Monad m => Producer ByteString m x -> FreeT (Producer ByteString m) m x
_lines :: Producer ByteString m x -> FreeT (Producer ByteString m) m x
_lines Producer ByteString m x
p0 = m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
-> FreeT (Producer ByteString m) m x
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (Producer ByteString m x
-> m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go0 Producer ByteString m x
p0)
where
go0 :: Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go0 Producer ByteString m a
p = do
Either a (ByteString, Producer ByteString m a)
x <- Producer ByteString m a
-> m (Either a (ByteString, Producer ByteString m a))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next Producer ByteString m a
p
case Either a (ByteString, Producer ByteString m a)
x of
Left a
r -> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (a
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure a
r)
Right (ByteString
bs, Producer ByteString m a
p') ->
if (ByteString -> Bool
BS.null ByteString
bs)
then Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go0 Producer ByteString m a
p'
else FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)))
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall a b. (a -> b) -> a -> b
$ Proxy X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. f b -> FreeF f a b
PG.Free (Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ Producer ByteString m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
go1 (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs Proxy X () () ByteString m ()
-> Producer ByteString m a -> Producer ByteString m a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m a
p')
go1 :: Producer ByteString m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
go1 Producer ByteString m a
p = do
Producer ByteString m a
p' <- Producer ByteString m a
pProducer ByteString m a
-> ((Producer ByteString m (Producer ByteString m a)
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m (Producer ByteString m a)))
-> Producer ByteString m a
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m a))
-> Producer ByteString m (Producer ByteString m a)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(Producer ByteString m (Producer ByteString m a)
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m (Producer ByteString m a)))
-> Producer ByteString m a
-> Constant
(Producer ByteString m (Producer ByteString m a))
(Producer ByteString m a)
forall (m :: * -> *) x.
Monad m =>
Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
line
FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
-> Proxy
X () () ByteString m (FreeT (Proxy X () () ByteString m) m a)
forall a b. (a -> b) -> a -> b
$ m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
-> FreeT (Proxy X () () ByteString m) m a
forall a b. (a -> b) -> a -> b
$ do
Either a (Word8, Producer ByteString m a)
x <- Producer ByteString m a
-> m (Either a (Word8, Producer ByteString m a))
forall (m :: * -> *) r.
Monad m =>
Producer ByteString m r
-> m (Either r (Word8, Producer ByteString m r))
nextByte Producer ByteString m a
p'
case Either a (Word8, Producer ByteString m a)
x of
Left a
r -> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
forall (m :: * -> *) a. Monad m => a -> m a
return (a
-> FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure a
r)
Right (Word8
_, Producer ByteString m a
p'') -> Producer ByteString m a
-> m (FreeF
(Proxy X () () ByteString m)
a
(FreeT (Proxy X () () ByteString m) m a))
go0 Producer ByteString m a
p''
{-# INLINABLE _lines #-}
_unlines
:: Monad m => FreeT (Producer ByteString m) m x -> Producer ByteString m x
_unlines :: FreeT (Producer ByteString m) m x -> Producer ByteString m x
_unlines = FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) a x.
Monad m =>
FreeT (Producer a m) m x -> Producer a m x
concats (FreeT (Producer ByteString m) m x -> Producer ByteString m x)
-> (FreeT (Producer ByteString m) m x
-> FreeT (Producer ByteString m) m x)
-> FreeT (Producer ByteString m) m x
-> Producer ByteString m x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall r. Producer ByteString m r -> Producer ByteString m r)
-> FreeT (Producer ByteString m) m x
-> FreeT (Producer ByteString m) m x
forall (m :: * -> *) (g :: * -> *) (f :: * -> *) x.
(Monad m, Functor g) =>
(forall r. f r -> g r) -> FreeT f m x -> FreeT g m x
PG.maps forall r. Producer ByteString m r -> Producer ByteString m r
forall (m :: * -> *) x' x a.
Functor m =>
Proxy x' x () ByteString m a -> Proxy x' x () ByteString m a
addNewline
where
addNewline :: Proxy x' x () ByteString m a -> Proxy x' x () ByteString m a
addNewline Proxy x' x () ByteString m a
p = Proxy x' x () ByteString m a
p Proxy x' x () ByteString m a
-> Proxy x' x () ByteString m () -> Proxy x' x () ByteString m a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ByteString -> Proxy x' x () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (Word8 -> ByteString
BS.singleton Word8
nl)
{-# INLINABLE _unlines #-}
words :: Monad m => Producer ByteString m x -> FreeT (Producer ByteString m) m x
words :: Producer ByteString m x -> FreeT (Producer ByteString m) m x
words Producer ByteString m x
p = m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
-> FreeT (Producer ByteString m) m x
forall (f :: * -> *) (m :: * -> *) a.
m (FreeF f a (FreeT f m a)) -> FreeT f m a
PG.FreeT (m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
-> FreeT (Producer ByteString m) m x)
-> m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
-> FreeT (Producer ByteString m) m x
forall a b. (a -> b) -> a -> b
$ do
Either x (ByteString, Producer ByteString m x)
x <- Producer ByteString m x
-> m (Either x (ByteString, Producer ByteString m x))
forall (m :: * -> *) a r.
Monad m =>
Producer a m r -> m (Either r (a, Producer a m r))
next ((Word8 -> Bool)
-> Producer ByteString m x -> Producer ByteString m x
forall (m :: * -> *) r.
Monad m =>
(Word8 -> Bool)
-> Producer ByteString m r -> Producer ByteString m r
dropWhile Word8 -> Bool
isSpaceWord8 Producer ByteString m x
p)
FreeF (Producer ByteString m) x (FreeT (Producer ByteString m) m x)
-> m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
forall (m :: * -> *) a. Monad m => a -> m a
return (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x)
-> m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x)))
-> FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x)
-> m (FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
forall a b. (a -> b) -> a -> b
$ case Either x (ByteString, Producer ByteString m x)
x of
Left x
r -> x
-> FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x)
forall (f :: * -> *) a b. a -> FreeF f a b
PG.Pure x
r
Right (ByteString
bs, Producer ByteString m x
p') -> Proxy X () () ByteString m (FreeT (Producer ByteString m) m x)
-> FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x)
forall (f :: * -> *) a b. f b -> FreeF f a b
PG.Free (Proxy X () () ByteString m (FreeT (Producer ByteString m) m x)
-> FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x))
-> Proxy X () () ByteString m (FreeT (Producer ByteString m) m x)
-> FreeF
(Producer ByteString m) x (FreeT (Producer ByteString m) m x)
forall a b. (a -> b) -> a -> b
$ do
Producer ByteString m x
p'' <- (ByteString -> Proxy X () () ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield ByteString
bs Proxy X () () ByteString m ()
-> Producer ByteString m x -> Producer ByteString m x
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Producer ByteString m x
p')Producer ByteString m x
-> ((Producer ByteString m (Producer ByteString m x)
-> Constant
(Producer ByteString m (Producer ByteString m x))
(Producer ByteString m (Producer ByteString m x)))
-> Producer ByteString m x
-> Constant
(Producer ByteString m (Producer ByteString m x))
(Producer ByteString m x))
-> Producer ByteString m (Producer ByteString m x)
forall a b. a -> ((b -> Constant b b) -> a -> Constant b a) -> b
^.(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
forall (m :: * -> *) x.
Monad m =>
(Word8 -> Bool)
-> Lens'
(Producer ByteString m x)
(Producer ByteString m (Producer ByteString m x))
break Word8 -> Bool
isSpaceWord8
FreeT (Producer ByteString m) m x
-> Proxy X () () ByteString m (FreeT (Producer ByteString m) m x)
forall (m :: * -> *) a. Monad m => a -> m a
return (Producer ByteString m x -> FreeT (Producer ByteString m) m x
forall (m :: * -> *) a.
Monad m =>
Producer ByteString m a -> FreeT (Proxy X () () ByteString m) m a
words Producer ByteString m x
p'')
{-# INLINABLE words #-}
unwords
:: Monad m => FreeT (Producer ByteString m) m x -> Producer ByteString m x
unwords :: FreeT (Producer ByteString m) m x -> Producer ByteString m x
unwords = Producer ByteString m ()
-> FreeT (Producer ByteString m) m x -> Producer ByteString m x
forall (m :: * -> *) a x.
Monad m =>
Producer a m () -> FreeT (Producer a m) m x -> Producer a m x
PG.intercalates (ByteString -> Producer ByteString m ()
forall (m :: * -> *) a x' x. Functor m => a -> Proxy x' x () a m ()
yield (ByteString -> Producer ByteString m ())
-> ByteString -> Producer ByteString m ()
forall a b. (a -> b) -> a -> b
$ Word8 -> ByteString
BS.singleton (Word8 -> ByteString) -> Word8 -> ByteString
forall a b. (a -> b) -> a -> b
$ Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ Char -> Int
ord Char
' ')
{-# INLINABLE unwords #-}