Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Producer/Consumer datatypes

  • Loading branch information...
commit 45fe6da7b298daed8befa9395bd9ebdf8d799801 1 parent 75ac21f
@snoyberg authored
View
10 attoparsec-conduit/Data/Conduit/Attoparsec.hs
@@ -34,7 +34,7 @@ import Control.Monad (unless)
import qualified Data.Attoparsec.ByteString
import qualified Data.Attoparsec.Text
import qualified Data.Attoparsec.Types as A
-import Data.Conduit hiding (Pipe, Sink, Conduit, Source)
+import Data.Conduit
-- | The context and message from a 'A.Fail' value.
data ParseError = ParseError
@@ -113,19 +113,19 @@ instance AttoparsecInput T.Text where
-- If parsing fails, a 'ParseError' will be thrown with 'monadThrow'.
--
-- Since 0.5.0
-sinkParser :: (AttoparsecInput a, MonadThrow m) => A.Parser a b -> GLSink a m b
+sinkParser :: (AttoparsecInput a, MonadThrow m) => A.Parser a b -> Consumer a m b
sinkParser = fmap snd . sinkParserPos (Position 1 1)
-- | Consume a stream of parsed tokens, returning both the token and the
-- position it appears at.
--
-- Since 0.5.0
-conduitParser :: (AttoparsecInput a, MonadThrow m) => A.Parser a b -> GLInfConduit a m (PositionRange, b)
+conduitParser :: (AttoparsecInput a, MonadThrow m) => A.Parser a b -> Conduit a m (PositionRange, b)
conduitParser parser =
conduit $ Position 1 0
where
conduit pos =
- awaitE >>= either return go
+ await >>= maybe (return ()) go
where
go x = do
leftover x
@@ -133,7 +133,7 @@ conduitParser parser =
yield (PositionRange pos pos', res)
conduit pos'
-sinkParserPos :: (AttoparsecInput a, MonadThrow m) => Position -> A.Parser a b -> GLSink a m (Position, b)
+sinkParserPos :: (AttoparsecInput a, MonadThrow m) => Position -> A.Parser a b -> Consumer a m (Position, b)
sinkParserPos pos0 =
sink empty pos0 . parseA
where
View
14 base64-conduit/Data/Conduit/Base64.hs
@@ -17,27 +17,27 @@ import qualified Data.ByteString.Base64.URL as B64U
import Data.Conduit
-encode :: Monad m => GInfConduit ByteString m ByteString
+encode :: Monad m => Conduit ByteString m ByteString
encode = codeWith 3 B64.encode
-decode :: Monad m => GInfConduit ByteString m ByteString
+decode :: Monad m => Conduit ByteString m ByteString
decode = codeWith 4 B64.decodeLenient
-encodeURL :: Monad m => GInfConduit ByteString m ByteString
+encodeURL :: Monad m => Conduit ByteString m ByteString
encodeURL = codeWith 3 B64U.encode
-decodeURL :: Monad m => GInfConduit ByteString m ByteString
+decodeURL :: Monad m => Conduit ByteString m ByteString
decodeURL = codeWith 4 B64U.decodeLenient
-codeWith :: Monad m => Int -> (ByteString -> ByteString) -> GInfConduit ByteString m ByteString
+codeWith :: Monad m => Int -> (ByteString -> ByteString) -> Conduit ByteString m ByteString
codeWith size f =
loop
where
- loop = awaitE >>= either return push
+ loop = await >>= maybe (return ()) push
loopWith bs
| S.null bs = loop
- | otherwise = awaitE >>= either (\r -> yield (f bs) >> return r) (pushWith bs)
+ | otherwise = await >>= maybe (yield (f bs)) (pushWith bs)
push bs = do
let (x, y) = S.splitAt (len - (len `mod` size)) bs
View
27 blaze-builder-conduit/Data/Conduit/Blaze.hs
@@ -42,7 +42,7 @@ module Data.Conduit.Blaze
, reuseBufferStrategy
) where
-import Data.Conduit hiding (Source, Conduit, Sink, Pipe)
+import Data.Conduit
import Control.Monad (unless, liftM)
import Control.Monad.Trans.Class (lift, MonadTrans)
@@ -54,14 +54,14 @@ import Blaze.ByteString.Builder.Internal.Buffer
-- | Incrementally execute builders and pass on the filled chunks as
-- bytestrings.
-builderToByteString :: MonadUnsafeIO m => GInfConduit Builder m S.ByteString
+builderToByteString :: MonadUnsafeIO m => Conduit Builder m S.ByteString
builderToByteString =
builderToByteStringWith (allNewBuffersStrategy defaultBufferSize)
-- |
--
-- Since 0.0.2
-builderToByteStringFlush :: MonadUnsafeIO m => GInfConduit (Flush Builder) m (Flush S.ByteString)
+builderToByteStringFlush :: MonadUnsafeIO m => Conduit (Flush Builder) m (Flush S.ByteString)
builderToByteStringFlush =
builderToByteStringWithFlush (allNewBuffersStrategy defaultBufferSize)
@@ -74,7 +74,7 @@ builderToByteStringFlush =
-- as control is returned from the inner sink!
unsafeBuilderToByteString :: MonadUnsafeIO m
=> IO Buffer -- action yielding the inital buffer.
- -> GInfConduit Builder m S.ByteString
+ -> Conduit Builder m S.ByteString
unsafeBuilderToByteString = builderToByteStringWith . reuseBufferStrategy
@@ -84,9 +84,9 @@ unsafeBuilderToByteString = builderToByteStringWith . reuseBufferStrategy
-- INV: All bytestrings passed to the inner sink are non-empty.
builderToByteStringWith :: MonadUnsafeIO m
=> BufferAllocStrategy
- -> GInfConduit Builder m S.ByteString
+ -> Conduit Builder m S.ByteString
builderToByteStringWith =
- helper (liftM (fmap Chunk) awaitE) yield'
+ helper (liftM (fmap Chunk) await) yield'
where
yield' Flush = return ()
yield' (Chunk bs) = yield bs
@@ -97,27 +97,26 @@ builderToByteStringWith =
builderToByteStringWithFlush
:: MonadUnsafeIO m
=> BufferAllocStrategy
- -> GInfConduit (Flush Builder) m (Flush S.ByteString)
-builderToByteStringWithFlush = helper awaitE yield
+ -> Conduit (Flush Builder) m (Flush S.ByteString)
+builderToByteStringWithFlush = helper await yield
helper :: (MonadUnsafeIO m, Monad (t m), MonadTrans t)
- => t m (Either term (Flush Builder))
+ => t m (Maybe (Flush Builder))
-> (Flush S.ByteString -> t m ())
-> BufferAllocStrategy
- -> t m term
-helper awaitE' yield' (ioBufInit, nextBuf) =
+ -> t m ()
+helper await' yield' (ioBufInit, nextBuf) =
loop ioBufInit
where
loop ioBuf = do
- awaitE' >>= either (close ioBuf) (cont' ioBuf)
+ await' >>= maybe (close ioBuf) (cont' ioBuf)
cont' ioBuf Flush = push ioBuf flush $ \ioBuf' -> yield' Flush >> loop ioBuf'
cont' ioBuf (Chunk builder) = push ioBuf builder loop
- close ioBuf r = do
+ close ioBuf = do
buf <- lift $ unsafeLiftIO $ ioBuf
maybe (return ()) (yield' . Chunk) (unsafeFreezeNonEmptyBuffer buf)
- return r
push ioBuf0 x continue = do
go (unBuilder x (buildStep finalStep)) ioBuf0
View
8 conduit/Data/Conduit.hs
@@ -39,9 +39,8 @@ module Data.Conduit
-- * Generalized conduit types
-- $generalizedConduitTypes
- , GSource
- , GSink
- , GConduit
+ , Producer
+ , Consumer
-- * Flushing
, Flush (..)
@@ -62,7 +61,6 @@ module Data.Conduit
import Control.Monad.Trans.Resource
import Data.Conduit.Internal hiding (await, awaitForever, yield, yieldOr, leftover, bracketP, addCleanup, transPipe, mapOutput, mapOutputMaybe, mapInput)
import qualified Data.Conduit.Internal as CI
-import Data.Void (Void)
{- $conduitInterface
@@ -515,7 +513,7 @@ instance Functor Flush where
fmap _ Flush = Flush
fmap f (Chunk a) = Chunk (f a)
-await :: Monad m => GSink i m (Maybe i)
+await :: Monad m => Consumer i m (Maybe i)
await = ConduitM CI.await
mapOutput :: Monad m => (o1 -> o2) -> ConduitM i o1 m r -> ConduitM i o2 m r
View
34 conduit/Data/Conduit/Binary.hs
@@ -35,7 +35,7 @@ module Data.Conduit.Binary
import Prelude hiding (head, take, drop, takeWhile, dropWhile)
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
-import Data.Conduit hiding (Source, Conduit, Sink)
+import Data.Conduit
import Data.Conduit.List (sourceList)
import Control.Exception (assert)
import Control.Monad (unless)
@@ -54,7 +54,7 @@ import qualified System.PosixFile as F
-- Since 0.3.0
sourceFile :: MonadResource m
=> FilePath
- -> GSource m S.ByteString
+ -> Producer m S.ByteString
sourceFile fp =
#if CABAL_OS_WINDOWS || NO_HANDLES
bracketP
@@ -74,7 +74,7 @@ sourceFile fp =
-- Since 0.3.0
sourceHandle :: MonadIO m
=> IO.Handle
- -> GSource m S.ByteString
+ -> Producer m S.ByteString
sourceHandle h =
loop
where
@@ -92,7 +92,7 @@ sourceHandle h =
-- Since 0.3.0
sourceIOHandle :: MonadResource m
=> IO IO.Handle
- -> GSource m S.ByteString
+ -> Producer m S.ByteString
sourceIOHandle alloc = bracketP alloc IO.hClose sourceHandle
-- | Stream all incoming data to the given 'IO.Handle'. Note that this function
@@ -101,7 +101,7 @@ sourceIOHandle alloc = bracketP alloc IO.hClose sourceHandle
-- Since 0.3.0
sinkHandle :: MonadIO m
=> IO.Handle
- -> GSink S.ByteString m ()
+ -> Consumer S.ByteString m ()
sinkHandle h = awaitForever $ liftIO . S.hPut h
-- | An alternative to 'sinkHandle'.
@@ -112,7 +112,7 @@ sinkHandle h = awaitForever $ liftIO . S.hPut h
-- Since 0.3.0
sinkIOHandle :: MonadResource m
=> IO IO.Handle
- -> GSink S.ByteString m ()
+ -> Consumer S.ByteString m ()
sinkIOHandle alloc = bracketP alloc IO.hClose sinkHandle
-- | Stream the contents of a file as binary data, starting from a certain
@@ -123,7 +123,7 @@ sourceFileRange :: MonadResource m
=> FilePath
-> Maybe Integer -- ^ Offset
-> Maybe Integer -- ^ Maximum count
- -> GSource m S.ByteString
+ -> Producer m S.ByteString
sourceFileRange fp offset count = bracketP
(IO.openBinaryFile fp IO.ReadMode)
IO.hClose
@@ -160,7 +160,7 @@ sourceFileRange fp offset count = bracketP
-- Since 0.3.0
sinkFile :: MonadResource m
=> FilePath
- -> GSink S.ByteString m ()
+ -> Consumer S.ByteString m ()
sinkFile fp = sinkIOHandle (IO.openBinaryFile fp IO.WriteMode)
-- | Stream the contents of the input to a file, and also send it along the
@@ -169,7 +169,7 @@ sinkFile fp = sinkIOHandle (IO.openBinaryFile fp IO.WriteMode)
-- Since 0.3.0
conduitFile :: MonadResource m
=> FilePath
- -> GConduit S.ByteString m S.ByteString
+ -> Conduit S.ByteString m S.ByteString
conduitFile fp = bracketP
(IO.openBinaryFile fp IO.WriteMode)
IO.hClose
@@ -184,7 +184,7 @@ conduitFile fp = bracketP
-- Since 0.3.0
isolate :: Monad m
=> Int
- -> GConduit S.ByteString m S.ByteString
+ -> Conduit S.ByteString m S.ByteString
isolate =
loop
where
@@ -204,7 +204,7 @@ isolate =
-- | Return the next byte from the stream, if available.
--
-- Since 0.3.0
-head :: Monad m => GSink S.ByteString m (Maybe Word8)
+head :: Monad m => Consumer S.ByteString m (Maybe Word8)
head = do
mbs <- await
case mbs of
@@ -217,7 +217,7 @@ head = do
-- | Return all bytes while the predicate returns @True@.
--
-- Since 0.3.0
-takeWhile :: Monad m => (Word8 -> Bool) -> GConduit S.ByteString m S.ByteString
+takeWhile :: Monad m => (Word8 -> Bool) -> Conduit S.ByteString m S.ByteString
takeWhile p =
loop
where
@@ -233,7 +233,7 @@ takeWhile p =
-- | Ignore all bytes while the predicate returns @True@.
--
-- Since 0.3.0
-dropWhile :: Monad m => (Word8 -> Bool) -> GSink S.ByteString m ()
+dropWhile :: Monad m => (Word8 -> Bool) -> Consumer S.ByteString m ()
dropWhile p =
loop
where
@@ -248,7 +248,7 @@ dropWhile p =
-- | Take the given number of bytes, if available.
--
-- Since 0.3.0
-take :: Monad m => Int -> GSink S.ByteString m L.ByteString
+take :: Monad m => Int -> Consumer S.ByteString m L.ByteString
take n0 =
go n0 id
where
@@ -266,7 +266,7 @@ take n0 =
-- | Drop up to the given number of bytes.
--
-- Since 0.5.0
-drop :: Monad m => Int -> GSink S.ByteString m ()
+drop :: Monad m => Int -> Consumer S.ByteString m ()
drop =
go
where
@@ -285,7 +285,7 @@ drop =
-- (10), and strip it from the output.
--
-- Since 0.3.0
-lines :: Monad m => GConduit S.ByteString m S.ByteString
+lines :: Monad m => Conduit S.ByteString m S.ByteString
lines =
loop id
where
@@ -307,5 +307,5 @@ lines =
-- | Stream the chunks from a lazy bytestring.
--
-- Since 0.5.0
-sourceLbs :: Monad m => L.ByteString -> GSource m S.ByteString
+sourceLbs :: Monad m => L.ByteString -> Producer m S.ByteString
sourceLbs = sourceList . L.toChunks
View
14 conduit/Data/Conduit/Internal.hs
@@ -10,11 +10,10 @@ module Data.Conduit.Internal
Pipe (..)
, ConduitM (..)
, Source
- , GSource
+ , Producer
, Sink
- , GSink
+ , Consumer
, Conduit
- , GConduit
, ResumableSource (..)
-- * Primitives
, await
@@ -155,7 +154,7 @@ type Source m o = ConduitM () o m ()
-- | Generalized 'Source'.
--
-- Since 0.5.0
-type GSource m o = forall i. ConduitM i o m ()
+type Producer m o = forall i. ConduitM i o m ()
-- | Consumes a stream of input values and produces a final result, without
-- producing any output.
@@ -166,7 +165,7 @@ type Sink i m r = ConduitM i Void m r
-- | Generalized 'Sink' without leftovers.
--
-- Since 0.5.0
-type GSink i m r = forall o. ConduitM i o m r
+type Consumer i m r = forall o. ConduitM i o m r
-- | Consumes a stream of input values and produces a stream of output values,
-- without producing a final result.
@@ -174,11 +173,6 @@ type GSink i m r = forall o. ConduitM i o m r
-- Since 0.5.0
type Conduit i m o = ConduitM i o m ()
--- | Generalized conduit without leftovers.
---
--- Since 0.5.0
-type GConduit i m o = Conduit i m o
-
-- | A @Source@ which has been started, but has not yet completed.
--
-- This type contains both the current state of the @Source@, and the finalizer
View
62 conduit/Data/Conduit/List.hs
@@ -62,7 +62,7 @@ import Prelude
, either
)
import Data.Monoid (Monoid, mempty, mappend)
-import Data.Conduit hiding (Source, Sink, Conduit)
+import Data.Conduit
import Control.Monad (when, (<=<))
import Control.Monad.Trans.Class (lift)
@@ -72,7 +72,7 @@ import Control.Monad.Trans.Class (lift)
unfold :: Monad m
=> (b -> Maybe (a, b))
-> b
- -> GSource m a
+ -> Producer m a
unfold f =
go
where
@@ -81,7 +81,7 @@ unfold f =
Just (a, seed') -> yield a >> go seed'
Nothing -> return ()
-sourceList :: Monad m => [a] -> GSource m a
+sourceList :: Monad m => [a] -> Producer m a
sourceList = Prelude.mapM_ yield
-- | Enumerate from a value to a final value, inclusive, via 'succ'.
@@ -94,7 +94,7 @@ sourceList = Prelude.mapM_ yield
enumFromTo :: (Enum a, Eq a, Monad m)
=> a
-> a
- -> GSource m a
+ -> Producer m a
enumFromTo start stop =
go start
where
@@ -103,7 +103,7 @@ enumFromTo start stop =
| otherwise = yield i >> go (succ i)
-- | Produces an infinite stream of repeated applications of f to x.
-iterate :: Monad m => (a -> a) -> a -> GSource m a
+iterate :: Monad m => (a -> a) -> a -> Producer m a
iterate f =
go
where
@@ -115,7 +115,7 @@ iterate f =
fold :: Monad m
=> (b -> a -> b)
-> b
- -> GSink a m b
+ -> Consumer a m b
fold f =
loop
where
@@ -132,7 +132,7 @@ fold f =
foldM :: Monad m
=> (b -> a -> m b)
-> b
- -> GSink a m b
+ -> Consumer a m b
foldM f =
loop
where
@@ -148,7 +148,7 @@ foldM f =
-- Since 0.5.3
foldMap :: (Monad m, Monoid b)
=> (a -> b)
- -> GSink a m b
+ -> Consumer a m b
foldMap f =
fold combiner mempty
where
@@ -159,7 +159,7 @@ foldMap f =
-- Since 0.3.0
mapM_ :: Monad m
=> (a -> m ())
- -> GSink a m ()
+ -> Consumer a m ()
mapM_ f = awaitForever $ lift . f
-- | Ignore a certain number of values in the stream. This function is
@@ -173,7 +173,7 @@ mapM_ f = awaitForever $ lift . f
-- Since 0.3.0
drop :: Monad m
=> Int
- -> GSink a m ()
+ -> Consumer a m ()
drop =
loop
where
@@ -189,7 +189,7 @@ drop =
-- Since 0.3.0
take :: Monad m
=> Int
- -> GSink a m [a]
+ -> Consumer a m [a]
take =
loop id
where
@@ -201,20 +201,20 @@ take =
-- | Take a single value from the stream, if available.
--
-- Since 0.3.0
-head :: Monad m => GSink a m (Maybe a)
+head :: Monad m => Consumer a m (Maybe a)
head = await
-- | Look at the next value in the stream, if available. This function will not
-- change the state of the stream.
--
-- Since 0.3.0
-peek :: Monad m => GSink a m (Maybe a)
+peek :: Monad m => Consumer a m (Maybe a)
peek = await >>= maybe (return Nothing) (\x -> leftover x >> return (Just x))
-- | Apply a transformation to all values in a stream.
--
-- Since 0.3.0
-map :: Monad m => (a -> b) -> GConduit a m b
+map :: Monad m => (a -> b) -> Conduit a m b
map f = awaitForever $ yield . f
{-
@@ -245,7 +245,7 @@ differences based on leftovers.
-- side-effects of running the action, see 'mapM_'.
--
-- Since 0.3.0
-mapM :: Monad m => (a -> m b) -> GConduit a m b
+mapM :: Monad m => (a -> m b) -> Conduit a m b
mapM f = awaitForever $ yield <=< lift . f
-- | Apply a monadic action on all values in a stream.
@@ -256,47 +256,47 @@ mapM f = awaitForever $ yield <=< lift . f
-- > iterM f = mapM (\a -> f a >>= \() -> return a)
--
-- Since 0.5.6
-iterM :: Monad m => (a -> m ()) -> GConduit a m a
+iterM :: Monad m => (a -> m ()) -> Conduit a m a
iterM f = awaitForever $ \a -> lift (f a) >> yield a
-- | Apply a transformation that may fail to all values in a stream, discarding
-- the failures.
--
-- Since 0.5.1
-mapMaybe :: Monad m => (a -> Maybe b) -> GConduit a m b
+mapMaybe :: Monad m => (a -> Maybe b) -> Conduit a m b
mapMaybe f = awaitForever $ maybe (return ()) yield . f
-- | Apply a monadic transformation that may fail to all values in a stream,
-- discarding the failures.
--
-- Since 0.5.1
-mapMaybeM :: Monad m => (a -> m (Maybe b)) -> GConduit a m b
+mapMaybeM :: Monad m => (a -> m (Maybe b)) -> Conduit a m b
mapMaybeM f = awaitForever $ maybe (return ()) yield <=< lift . f
-- | Filter the @Just@ values from a stream, discarding the @Nothing@ values.
--
-- Since 0.5.1
-catMaybes :: Monad m => GConduit (Maybe a) m a
+catMaybes :: Monad m => Conduit (Maybe a) m a
catMaybes = awaitForever $ maybe (return ()) yield
-- | Apply a transformation to all values in a stream, concatenating the output
-- values.
--
-- Since 0.3.0
-concatMap :: Monad m => (a -> [b]) -> GConduit a m b
+concatMap :: Monad m => (a -> [b]) -> Conduit a m b
concatMap f = awaitForever $ sourceList . f
-- | Apply a monadic transformation to all values in a stream, concatenating
-- the output values.
--
-- Since 0.3.0
-concatMapM :: Monad m => (a -> m [b]) -> GConduit a m b
+concatMapM :: Monad m => (a -> m [b]) -> Conduit a m b
concatMapM f = awaitForever $ sourceList <=< lift . f
-- | 'concatMap' with an accumulator.
--
-- Since 0.3.0
-concatMapAccum :: Monad m => (a -> accum -> (accum, [b])) -> accum -> GConduit a m b
+concatMapAccum :: Monad m => (a -> accum -> (accum, [b])) -> accum -> Conduit a m b
concatMapAccum f =
loop
where
@@ -311,7 +311,7 @@ concatMapAccum f =
-- | 'concatMapM' with an accumulator.
--
-- Since 0.3.0
-concatMapAccumM :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> GConduit a m b
+concatMapAccumM :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> Conduit a m b
concatMapAccumM f =
loop
where
@@ -328,7 +328,7 @@ concatMapAccumM f =
-- "Data.Conduit.Lazy".
--
-- Since 0.3.0
-consume :: Monad m => GSink a m [a]
+consume :: Monad m => Consumer a m [a]
consume =
loop id
where
@@ -337,7 +337,7 @@ consume =
-- | Grouping input according to an equality function.
--
-- Since 0.3.0
-groupBy :: Monad m => (a -> a -> Bool) -> GConduit a m [a]
+groupBy :: Monad m => (a -> a -> Bool) -> Conduit a m [a]
groupBy f =
start
where
@@ -363,7 +363,7 @@ groupBy f =
-- > ...
--
-- Since 0.3.0
-isolate :: Monad m => Int -> GConduit a m a
+isolate :: Monad m => Int -> Conduit a m a
isolate =
loop
where
@@ -373,21 +373,21 @@ isolate =
-- | Keep only values in the stream passing a given predicate.
--
-- Since 0.3.0
-filter :: Monad m => (a -> Bool) -> GConduit a m a
+filter :: Monad m => (a -> Bool) -> Conduit a m a
filter f = awaitForever $ \i -> when (f i) (yield i)
-- | Ignore the remainder of values in the source. Particularly useful when
-- combined with 'isolate'.
--
-- Since 0.3.0
-sinkNull :: Monad m => GSink a m ()
+sinkNull :: Monad m => Consumer a m ()
sinkNull = awaitForever $ \_ -> return ()
-- | A source that outputs no values. Note that this is just a type-restricted
-- synonym for 'mempty'.
--
-- Since 0.3.0
-sourceNull :: Monad m => GSource m a
+sourceNull :: Monad m => Producer m a
sourceNull = return ()
-- | Run a @Pipe@ repeatedly, and output its result value downstream. Stops
@@ -395,8 +395,8 @@ sourceNull = return ()
--
-- Since 0.5.0
sequence :: Monad m
- => GSink i m o -- ^ @Pipe@ to run repeatedly
- -> GConduit i m o
+ => Consumer i m o -- ^ @Pipe@ to run repeatedly
+ -> Conduit i m o
sequence sink =
self
where
View
8 conduit/Data/Conduit/Text.hs
@@ -40,7 +40,7 @@ import Data.Word (Word8, Word16)
import System.IO.Unsafe (unsafePerformIO)
import Data.Typeable (Typeable)
-import Data.Conduit hiding (Source, Conduit, Sink)
+import Data.Conduit
import qualified Data.Conduit.List as CL
import Control.Monad.Trans.Class (lift)
import Control.Monad (unless)
@@ -67,7 +67,7 @@ instance Show Codec where
-- | Emit each line separately
--
-- Since 0.4.1
-lines :: Monad m => GConduit T.Text m T.Text
+lines :: Monad m => Conduit T.Text m T.Text
lines =
loop id
where
@@ -90,7 +90,7 @@ lines =
-- not capable of representing an input character, an exception will be thrown.
--
-- Since 0.3.0
-encode :: MonadThrow m => Codec -> GConduit T.Text m B.ByteString
+encode :: MonadThrow m => Codec -> Conduit T.Text m B.ByteString
encode codec = CL.mapM $ \t -> do
let (bs, mexc) = codecEncode codec t
maybe (return bs) (monadThrow . fst) mexc
@@ -100,7 +100,7 @@ encode codec = CL.mapM $ \t -> do
-- not capable of decoding an input byte sequence, an exception will be thrown.
--
-- Since 0.3.0
-decode :: MonadThrow m => Codec -> GConduit B.ByteString m T.Text
+decode :: MonadThrow m => Codec -> Conduit B.ByteString m T.Text
decode codec =
loop id
where
View
1  conduit/conduit.cabal
@@ -81,6 +81,7 @@ test-suite test
ghc-options: -Wall
test-suite doctests
+ buildable: False
hs-source-dirs: test
main-is: doctests.hs
type: exitcode-stdio-1.0
View
6 filesystem-conduit/Data/Conduit/Filesystem.hs
@@ -42,7 +42,7 @@ import qualified System.Posix as Posix
traverse :: MonadIO m
=> Bool -- ^ Follow directory symlinks (only used on POSIX platforms)
-> FilePath -- ^ Root directory
- -> GSource m FilePath
+ -> Producer m FilePath
traverse _followSymlinks root =
liftIO (listDirectory root) >>= pull
where
@@ -75,11 +75,11 @@ traverse _followSymlinks root =
-- | Same as 'CB.sourceFile', but uses system-filepath\'s @FilePath@ type.
sourceFile :: MonadResource m
=> FilePath
- -> GSource m S.ByteString
+ -> Producer m S.ByteString
sourceFile = CB.sourceFile . encodeString
-- | Same as 'CB.sinkFile', but uses system-filepath\'s @FilePath@ type.
sinkFile :: MonadResource m
=> FilePath
- -> GInfSink S.ByteString m
+ -> Consumer S.ByteString m ()
sinkFile = CB.sinkFile . encodeString
View
6 imagesize-conduit/Data/Conduit/ImageSize.hs
@@ -22,14 +22,14 @@ data FileFormat = GIF | PNG | JPG
-- | Specialized version of 'sinkImageInfo' that returns only the
-- image size.
-sinkImageSize :: Monad m => GLSink S.ByteString m (Maybe Size)
+sinkImageSize :: Monad m => Consumer S.ByteString m (Maybe Size)
sinkImageSize = fmap (fmap fst) sinkImageInfo
-- | Find out the size of an image. Also returns the file format
-- that parsed correctly. Note that this function does not
-- verify that the file is indeed in the format that it returns,
-- since it looks only at a small part of the header.
-sinkImageInfo :: Monad m => GLSink S.ByteString m (Maybe (Size, FileFormat))
+sinkImageInfo :: Monad m => Consumer S.ByteString m (Maybe (Size, FileFormat))
sinkImageInfo =
start id
where
@@ -92,7 +92,7 @@ sinkImageInfo =
getInt :: (Monad m, Integral i)
=> Int
-> i
- -> Pipe S.ByteString S.ByteString o u m (Maybe i)
+ -> Consumer S.ByteString m (Maybe i)
getInt 0 i = return $ Just i
getInt len i = do
mx <- CB.head
View
6 network-conduit/Data/Conduit/Network.hs
@@ -57,7 +57,7 @@ import qualified Data.Conduit.Network.Utils as Utils
-- This function does /not/ automatically close the socket.
--
-- Since 0.0.0
-sourceSocket :: MonadIO m => Socket -> GSource m ByteString
+sourceSocket :: MonadIO m => Socket -> Producer m ByteString
sourceSocket socket =
loop
where
@@ -72,11 +72,11 @@ sourceSocket socket =
-- This function does /not/ automatically close the socket.
--
-- Since 0.0.0
-sinkSocket :: MonadIO m => Socket -> GInfSink ByteString m
+sinkSocket :: MonadIO m => Socket -> Consumer ByteString m ()
sinkSocket socket =
loop
where
- loop = awaitE >>= either return (\bs -> lift (liftIO $ sendAll socket bs) >> loop)
+ loop = await >>= maybe (return ()) (\bs -> lift (liftIO $ sendAll socket bs) >> loop)
-- | A simple TCP application.
--
View
16 network-conduit/Data/Conduit/Network/UDP.hs
@@ -37,7 +37,7 @@ data Message = Message { msgData :: {-# UNPACK #-} !ByteString
-- contains the message payload and the origin address.
--
-- This function does /not/ automatically close the socket.
-sourceSocket :: MonadIO m => Socket -> Int -> GSource m Message
+sourceSocket :: MonadIO m => Socket -> Int -> Producer m Message
sourceSocket socket len = loop
where
loop = do
@@ -49,7 +49,7 @@ sourceSocket socket len = loop
-- The payload is sent using @send@, so some of it might be lost.
--
-- This function does /not/ automatically close the socket.
-sinkSocket :: MonadIO m => Socket -> GInfSink ByteString m
+sinkSocket :: MonadIO m => Socket -> Consumer ByteString m ()
sinkSocket = sinkSocketHelper (\sock bs -> void $ send sock bs)
-- | Stream messages to the connected socket.
@@ -57,7 +57,7 @@ sinkSocket = sinkSocketHelper (\sock bs -> void $ send sock bs)
-- The payload is sent using @sendAll@, so it might end up in multiple packets.
--
-- This function does /not/ automatically close the socket.
-sinkAllSocket :: MonadIO m => Socket -> GInfSink ByteString m
+sinkAllSocket :: MonadIO m => Socket -> Consumer ByteString m ()
sinkAllSocket = sinkSocketHelper sendAll
-- | Stream messages to the socket.
@@ -67,7 +67,7 @@ sinkAllSocket = sinkSocketHelper sendAll
-- lost.
--
-- This function does /not/ automatically close the socket.
-sinkToSocket :: MonadIO m => Socket -> GInfSink Message m
+sinkToSocket :: MonadIO m => Socket -> Consumer Message m ()
sinkToSocket = sinkSocketHelper (\sock (Message bs addr) -> void $ sendTo sock bs addr)
-- | Stream messages to the socket.
@@ -77,7 +77,7 @@ sinkToSocket = sinkSocketHelper (\sock (Message bs addr) -> void $ sendTo sock b
-- multiple packets.
--
-- This function does /not/ automatically close the socket.
-sinkAllToSocket :: MonadIO m => Socket -> GInfSink Message m
+sinkAllToSocket :: MonadIO m => Socket -> Consumer Message m ()
sinkAllToSocket = sinkSocketHelper (\sock (Message bs addr) -> sendAllTo sock bs addr)
-- | Attempt to connect to the given host/port.
@@ -92,10 +92,10 @@ bindPort p s = Utils.bindPort p s NS.Datagram
-- Internal
sinkSocketHelper :: MonadIO m => (Socket -> a -> IO ())
-> Socket
- -> GInfSink a m
+ -> Consumer a m ()
sinkSocketHelper act socket = loop
where
- loop = awaitE >>= either
- return
+ loop = await >>= maybe
+ (return ())
(\a -> lift (liftIO $ act socket a) >> loop)
{-# INLINE sinkSocketHelper #-}
View
51 zlib-conduit/Data/Conduit/Zlib.hs
@@ -13,7 +13,7 @@ module Data.Conduit.Zlib (
) where
import Codec.Zlib
-import Data.Conduit hiding (unsafeLiftIO, Source, Sink, Conduit, Pipe)
+import Data.Conduit hiding (unsafeLiftIO)
import qualified Data.Conduit as C (unsafeLiftIO)
import Data.ByteString (ByteString)
import qualified Data.ByteString as S
@@ -22,11 +22,11 @@ import Control.Monad ((<=<), unless, liftM)
import Control.Monad.Trans.Class (lift, MonadTrans)
-- | Gzip compression with default parameters.
-gzip :: (MonadThrow m, MonadUnsafeIO m) => GInfConduit ByteString m ByteString
+gzip :: (MonadThrow m, MonadUnsafeIO m) => Conduit ByteString m ByteString
gzip = compress 1 (WindowBits 31)
-- | Gzip decompression with default parameters.
-ungzip :: (MonadUnsafeIO m, MonadThrow m) => GInfConduit ByteString m ByteString
+ungzip :: (MonadUnsafeIO m, MonadThrow m) => Conduit ByteString m ByteString
ungzip = decompress (WindowBits 31)
unsafeLiftIO :: (MonadUnsafeIO m, MonadThrow m) => IO a -> m a
@@ -44,9 +44,9 @@ unsafeLiftIO =
decompress
:: (MonadUnsafeIO m, MonadThrow m)
=> WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)
- -> GInfConduit ByteString m ByteString
+ -> Conduit ByteString m ByteString
decompress =
- helperDecompress (liftM (fmap Chunk) awaitE) yield'
+ helperDecompress (liftM (fmap Chunk) await) yield'
where
yield' Flush = return ()
yield' (Chunk bs) = yield bs
@@ -55,22 +55,22 @@ decompress =
decompressFlush
:: (MonadUnsafeIO m, MonadThrow m)
=> WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)
- -> GInfConduit (Flush ByteString) m (Flush ByteString)
-decompressFlush = helperDecompress awaitE yield
+ -> Conduit (Flush ByteString) m (Flush ByteString)
+decompressFlush = helperDecompress await yield
helperDecompress :: (Monad (t m), MonadUnsafeIO m, MonadThrow m, MonadTrans t)
- => t m (Either term (Flush ByteString))
+ => t m (Maybe (Flush ByteString))
-> (Flush ByteString -> t m ())
-> WindowBits
- -> t m term
-helperDecompress awaitE' yield' config =
- awaitE' >>= either return start
+ -> t m ()
+helperDecompress await' yield' config =
+ await' >>= maybe (return ()) start
where
start input = do
inf <- lift $ unsafeLiftIO $ initInflate config
push inf input
- continue inf = awaitE' >>= either (close inf) (push inf)
+ continue inf = await' >>= maybe (close inf) (push inf)
goPopper popper = do
mbs <- lift $ unsafeLiftIO popper
@@ -89,10 +89,9 @@ helperDecompress awaitE' yield' config =
yield' Flush
continue inf
- close inf ret = do
+ close inf = do
chunk <- lift $ unsafeLiftIO $ finishInflate inf
unless (S.null chunk) $ yield' $ Chunk chunk
- return ret
-- |
-- Compress (deflate) a stream of 'ByteString's. The 'WindowBits' also control
@@ -102,9 +101,9 @@ compress
:: (MonadUnsafeIO m, MonadThrow m)
=> Int -- ^ Compression level
-> WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)
- -> GInfConduit ByteString m ByteString
+ -> Conduit ByteString m ByteString
compress =
- helperCompress (liftM (fmap Chunk) awaitE) yield'
+ helperCompress (liftM (fmap Chunk) await) yield'
where
yield' Flush = return ()
yield' (Chunk bs) = yield bs
@@ -114,23 +113,23 @@ compressFlush
:: (MonadUnsafeIO m, MonadThrow m)
=> Int -- ^ Compression level
-> WindowBits -- ^ Zlib parameter (see the zlib-bindings package as well as the zlib C library)
- -> GInfConduit (Flush ByteString) m (Flush ByteString)
-compressFlush = helperCompress awaitE yield
+ -> Conduit (Flush ByteString) m (Flush ByteString)
+compressFlush = helperCompress await yield
helperCompress :: (Monad (t m), MonadUnsafeIO m, MonadThrow m, MonadTrans t)
- => t m (Either term (Flush ByteString))
+ => t m (Maybe (Flush ByteString))
-> (Flush ByteString -> t m ())
-> Int
-> WindowBits
- -> t m term
-helperCompress awaitE' yield' level config =
- awaitE' >>= either return start
+ -> t m ()
+helperCompress await' yield' level config =
+ await' >>= maybe (return ()) start
where
start input = do
def <- lift $ unsafeLiftIO $ initDeflate level config
push def input
- continue def = awaitE' >>= either (close def) (push def)
+ continue def = await' >>= maybe (close def) (push def)
goPopper popper = do
mbs <- lift $ unsafeLiftIO popper
@@ -149,8 +148,8 @@ helperCompress awaitE' yield' level config =
yield' Flush
continue def
- close def ret = do
+ close def = do
mchunk <- lift $ unsafeLiftIO $ finishDeflate def
case mchunk of
- Nothing -> return ret
- Just chunk -> yield' (Chunk chunk) >> close def ret
+ Nothing -> return ()
+ Just chunk -> yield' (Chunk chunk) >> close def
Please sign in to comment.
Something went wrong with that request. Please try again.