Safe Haskell | None |
---|---|
Language | Haskell98 |
Please see the project README for more details:
https://github.com/jwiegley/simple-conduit/blob/master/README.md
Also see this blog article:
- newtype Source m a = Source {}
- type Conduit a m b = Source m a -> Source m b
- type Sink a m r = Source m a -> m r
- runSource :: Source m a -> r -> (r -> a -> EitherT r m r) -> EitherT r m r
- lowerSource :: (Monad m, Monoid a) => Source m a -> m a
- source :: (forall r. r -> (r -> a -> EitherT r m r) -> EitherT r m r) -> Source m a
- conduit :: (forall r. r -> (r -> b -> EitherT r m r) -> a -> EitherT r m r) -> Conduit a m b
- conduitWith :: Monad m => s -> (forall r. (r, s) -> (r -> b -> EitherT (r, s) m (r, s)) -> a -> EitherT (r, s) m (r, s)) -> Conduit a m b
- sink :: forall m a r. Monad m => r -> (r -> a -> EitherT r m r) -> Sink a m r
- returnC :: Monad m => m a -> Source m a
- close :: Monad m => Source m a
- skip :: Monad m => Source m a
- awaitForever :: (a -> Source m b) -> Conduit a m b
- yieldMany :: (Monad m, MonoFoldable mono) => mono -> Source m (Element mono)
- sourceList :: Monad m => [a] -> Source m a
- unfoldC :: forall m a b. Monad m => (b -> Maybe (a, b)) -> b -> Source m a
- enumFromToC :: forall m a. (Monad m, Enum a, Eq a) => a -> a -> Source m a
- iterateC :: forall m a. Monad m => (a -> a) -> a -> Source m a
- repeatC :: forall m a. Monad m => a -> Source m a
- replicateC :: forall m a. Monad m => Int -> a -> Source m a
- sourceLazy :: (Monad m, LazySequence lazy strict) => lazy -> Source m strict
- repeatMC :: forall m a. Monad m => m a -> Source m a
- repeatWhileMC :: forall m a. Monad m => m a -> (a -> Bool) -> Source m a
- replicateMC :: forall m a. Monad m => Int -> m a -> Source m a
- sourceHandle :: forall m a. (MonadIO m, MonoFoldable a, IOData a) => Handle -> Source m a
- sourceFile :: (MonadBaseControl IO m, MonadIO m, MonoFoldable a, IOData a) => FilePath -> Source m a
- sourceIOHandle :: (MonadBaseControl IO m, MonadIO m, MonoFoldable a, IOData a) => IO Handle -> Source m a
- stdinC :: (MonadBaseControl IO m, MonadIO m, MonoFoldable a, IOData a) => Source m a
- initRepeat :: Monad m => m seed -> (seed -> m a) -> Source m a
- initReplicate :: Monad m => m seed -> (seed -> m a) -> Int -> Source m a
- sourceRandom :: (Variate a, MonadIO m) => Source m a
- sourceRandomN :: (Variate a, MonadIO m) => Int -> Source m a
- sourceRandomGen :: (Variate a, MonadBase base m, PrimMonad base) => Gen (PrimState base) -> Source m a
- sourceRandomNGen :: (Variate a, MonadBase base m, PrimMonad base) => Gen (PrimState base) -> Int -> Source m a
- sourceDirectory :: forall m. MonadBaseControl IO m => FilePath -> Source m FilePath
- sourceDirectoryDeep :: forall m. MonadBaseControl IO m => Bool -> FilePath -> Source m FilePath
- dropC :: Monad m => Int -> Conduit a m a
- dropCE :: (Monad m, IsSequence seq) => Index seq -> Conduit seq m seq
- dropWhileC :: Monad m => (a -> Bool) -> Conduit a m a
- dropWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> Conduit seq m seq
- foldC :: (Monad m, Monoid a) => Sink a m a
- foldCE :: (Monad m, MonoFoldable mono, Monoid (Element mono)) => Sink mono m (Element mono)
- foldlC :: Monad m => (a -> b -> a) -> a -> Sink b m a
- foldlCE :: (Monad m, MonoFoldable mono) => (a -> Element mono -> a) -> a -> Sink mono m a
- foldMapC :: (Monad m, Monoid b) => (a -> b) -> Sink a m b
- foldMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> Sink mono m w
- allC :: Monad m => (a -> Bool) -> Sink a m Bool
- allCE :: (Monad m, MonoFoldable mono) => (Element mono -> Bool) -> Sink mono m Bool
- anyC :: Monad m => (a -> Bool) -> Sink a m Bool
- anyCE :: (Monad m, MonoFoldable mono) => (Element mono -> Bool) -> Sink mono m Bool
- andC :: Monad m => Sink Bool m Bool
- andCE :: (Monad m, MonoFoldable mono, Element mono ~ Bool) => Sink mono m Bool
- orC :: Monad m => Sink Bool m Bool
- orCE :: (Monad m, MonoFoldable mono, Element mono ~ Bool) => Sink mono m Bool
- elemC :: (Monad m, Eq a) => a -> Sink a m Bool
- elemCE :: (Monad m, MonoFoldable seq, Eq (Element seq)) => Element seq -> Sink seq m Bool
- notElemC :: (Monad m, Eq a) => a -> Sink a m Bool
- notElemCE :: (Monad m, MonoFoldable seq, Eq (Element seq)) => Element seq -> Sink seq m Bool
- sinkLazy :: (Monad m, LazySequence lazy strict) => Sink strict m lazy
- sinkList :: Monad m => Sink a m [a]
- sinkVector :: (MonadBase base m, Vector v a, PrimMonad base) => Sink a m (v a)
- sinkBuilder :: (Monad m, Monoid builder, ToBuilder a builder) => Sink a m builder
- sinkLazyBuilder :: (Monad m, Monoid builder, ToBuilder a builder, Builder builder lazy) => Sink a m lazy
- sinkNull :: Monad m => Sink a m ()
- awaitNonNull :: (Monad m, MonoFoldable a) => Conduit a m (Maybe (NonNull a))
- headCE :: (Monad m, IsSequence seq) => Sink seq m (Maybe (Element seq))
- lastC :: Monad m => Sink a m (Maybe a)
- lastCE :: (Monad m, IsSequence seq) => Sink seq m (Maybe (Element seq))
- lengthC :: (Monad m, Num len) => Sink a m len
- lengthCE :: (Monad m, Num len, MonoFoldable mono) => Sink mono m len
- lengthIfC :: (Monad m, Num len) => (a -> Bool) -> Sink a m len
- lengthIfCE :: (Monad m, Num len, MonoFoldable mono) => (Element mono -> Bool) -> Sink mono m len
- maximumC :: (Monad m, Ord a) => Sink a m (Maybe a)
- maximumCE :: (Monad m, MonoFoldable seq) => Sink seq m (Maybe (Element seq))
- minimumC :: (Monad m, Ord a) => Sink a m (Maybe a)
- minimumCE :: (Monad m, MonoFoldable seq) => Sink seq m (Maybe (Element seq))
- sumC :: (Monad m, Num a) => Sink a m a
- sumCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => Sink mono m (Element mono)
- productC :: (Monad m, Num a) => Sink a m a
- productCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => Sink mono m (Element mono)
- findC :: Monad m => (a -> Bool) -> Sink a m (Maybe a)
- mapM_C :: Monad m => (a -> m ()) -> Sink a m ()
- mapM_CE :: (Monad m, MonoFoldable mono) => (Element mono -> m ()) -> Sink mono m ()
- foldMC :: Monad m => (a -> b -> m a) -> a -> Sink b m a
- foldMCE :: (Monad m, MonoFoldable mono) => (a -> Element mono -> m a) -> a -> Sink mono m a
- foldMapMC :: (Monad m, Monoid w) => (a -> m w) -> Sink a m w
- foldMapMCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> m w) -> Sink mono m w
- sinkFile :: (MonadBaseControl IO m, MonadIO m, IOData a) => FilePath -> Sink a m ()
- sinkHandle :: (MonadIO m, IOData a) => Handle -> Sink a m ()
- sinkIOHandle :: (MonadBaseControl IO m, MonadIO m, IOData a) => IO Handle -> Sink a m ()
- printC :: (Show a, MonadIO m) => Sink a m ()
- stdoutC :: (MonadIO m, IOData a) => Sink a m ()
- stderrC :: (MonadIO m, IOData a) => Sink a m ()
- mapC :: Monad m => (a -> b) -> Conduit a m b
- mapCE :: (Monad m, Functor f) => (a -> b) -> Conduit (f a) m (f b)
- omapCE :: (Monad m, MonoFunctor mono) => (Element mono -> Element mono) -> Conduit mono m mono
- concatMapC :: (Monad m, MonoFoldable mono) => (a -> mono) -> Conduit a m (Element mono)
- concatMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> Conduit mono m w
- takeC :: Monad m => Int -> Conduit a m a
- takeCE :: (Monad m, IsSequence seq) => Index seq -> Conduit seq m seq
- takeWhileC :: Monad m => (a -> Bool) -> Conduit a m a
- takeWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> Conduit seq m seq
- takeExactlyC :: Monad m => Int -> Conduit a m b -> Conduit a m b
- takeExactlyCE :: (Monad m, IsSequence a) => Index a -> Conduit a m b -> Conduit a m b
- concatC :: (Monad m, MonoFoldable mono) => Conduit mono m (Element mono)
- filterC :: Monad m => (a -> Bool) -> Conduit a m a
- filterCE :: (IsSequence seq, Monad m) => (Element seq -> Bool) -> Conduit seq m seq
- mapWhileC :: Monad m => (a -> Maybe b) -> Conduit a m b
- conduitVector :: (MonadBase base m, Vector v a, PrimMonad base) => Int -> Conduit a m (v a)
- scanlC :: Monad m => (a -> b -> a) -> a -> Conduit b m a
- concatMapAccumC :: Monad m => (a -> accum -> (accum, [b])) -> accum -> Conduit a m b
- intersperseC :: Monad m => a -> Source m a -> Source m a
- encodeBase64C :: Monad m => Conduit ByteString m ByteString
- decodeBase64C :: Monad m => Conduit ByteString m ByteString
- encodeBase64URLC :: Monad m => Conduit ByteString m ByteString
- decodeBase64URLC :: Monad m => Conduit ByteString m ByteString
- encodeBase16C :: Monad m => Conduit ByteString m ByteString
- decodeBase16C :: Monad m => Conduit ByteString m ByteString
- mapMC :: Monad m => (a -> m b) -> Conduit a m b
- mapMCE :: (Monad m, Traversable f) => (a -> m b) -> Conduit (f a) m (f b)
- omapMCE :: (Monad m, MonoTraversable mono) => (Element mono -> m (Element mono)) -> Conduit mono m mono
- concatMapMC :: (Monad m, MonoFoldable mono) => (a -> m mono) -> Conduit a m (Element mono)
- filterMC :: Monad m => (a -> m Bool) -> Conduit a m a
- filterMCE :: (Monad m, IsSequence seq) => (Element seq -> m Bool) -> Conduit seq m seq
- iterMC :: Monad m => (a -> m ()) -> Conduit a m a
- scanlMC :: Monad m => (a -> b -> m a) -> a -> Conduit b m a
- concatMapAccumMC :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> Conduit a m b
- encodeUtf8C :: Monad m => Conduit Text m ByteString
- decodeUtf8C :: MonadThrow m => Conduit ByteString m Text
- lineC :: (Monad m, IsSequence seq, Element seq ~ Char) => Conduit seq m o -> Conduit seq m o
- lineAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => Conduit seq m o -> Conduit seq m o
- unlinesC :: (Monad m, IsSequence seq, Element seq ~ Char) => Conduit seq m seq
- unlinesAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => Conduit seq m seq
- linesUnboundedC_ :: forall m seq. (Monad m, IsSequence seq, Eq (Element seq), Semigroup seq) => Element seq -> Conduit seq m seq
- linesUnboundedC :: (Monad m, IsSequence seq, Element seq ~ Char, Semigroup seq) => Conduit seq m seq
- linesC :: (Monad m, IsSequence seq, Element seq ~ Char, Semigroup seq) => Conduit seq m seq
- linesUnboundedAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8, Semigroup seq) => Conduit seq m seq
- linesAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8, Semigroup seq) => Conduit seq m seq
- sourceMaybeMVar :: forall m a. MonadIO m => MVar (Maybe a) -> Source m a
- sourceMaybeTMVar :: forall a. TMVar (Maybe a) -> Source STM a
- asyncC :: (MonadBaseControl IO m, Monad m) => (a -> m b) -> Conduit a m (Async (StM m b))
- sourceTChan :: forall a. TChan a -> Source STM a
- sourceTQueue :: forall a. TQueue a -> Source STM a
- sourceTBQueue :: forall a. TBQueue a -> Source STM a
- untilMC :: forall m a. Monad m => m a -> m Bool -> Source m a
- whileMC :: forall m a. Monad m => m Bool -> m a -> Source m a
- zipSinks :: forall a m r r'. (MonadBaseControl IO m, MonadIO m) => Sink a m r -> Sink a m r' -> Sink a m (r, r')
- ($=) :: a -> (a -> b) -> b
- (=$) :: (a -> b) -> (b -> c) -> a -> c
- (=$=) :: (a -> b) -> (b -> c) -> a -> c
- ($$) :: a -> (a -> b) -> b
- sequenceSources :: (Traversable f, Monad m) => f (Source m a) -> Source m (f a)
Documentation
A Source is a short-circuiting monadic fold.
Source
forms a Monad that behaves as ListT
; for example:
do x <- yieldMany [1..3] line <- sourceFile "foo.txt" return (x, line)
This yields the cross-product of [3] and the lines in the files, but only reading chunks from the file as needed by the sink.
To skip to the next value in a Source, use the function skip
or mempty
;
to close the source, use close
. For example:
do x <- yieldMany [1..10] if x == 2 || x == 9 then return x else if x < 5 then skip else close
This outputs the list [2]
.
A key difference from the conduit
library is that monadic chaining of
sources with >>
follows ListT
, and not concatenation as in conduit. To
achieve conduit-style behavior, use the Monoid instance:
>>>
sinkList $ yieldMany [1..3] <> yieldMany [4..6]
[1,2,3,4,5,6]
MonadTrans Source Source # | |
MFunctor Source Source # | |
MMonad Source Source # | |
(Functor f, MonadFree f m) => MonadFree f (Source m) Source # | |
MonadError e m => MonadError e (Source m) Source # | |
MonadReader r m => MonadReader r (Source m) Source # | |
MonadState s m => MonadState s (Source m) Source # | |
MonadWriter w m => MonadWriter w (Source m) Source # | |
Monad (Source m) Source # | |
Functor (Source m) Source # | |
Applicative (Source m) Source # | |
Foldable (Source Identity) Source # | |
Monad m => MonadPlus (Source m) Source # | |
MonadIO m => MonadIO (Source m) Source # | |
Monad m => Alternative (Source m) Source # | |
MonadThrow m => MonadThrow (Source m) Source # | |
MonadCatch m => MonadCatch (Source m) Source # | |
MonadMask m => MonadMask (Source m) Source # | |
Monad m => Semigroup (Source m a) Source # | |
Monad m => Monoid (Source m a) Source # | |
type Conduit a m b = Source m a -> Source m b Source #
A Conduit
is a "Source homomorphism", or simple a mapping between
sources. There is no need for it to be a type synonym, except to save
repetition across type signatures.
conduit :: (forall r. r -> (r -> b -> EitherT r m r) -> a -> EitherT r m r) -> Conduit a m b Source #
conduitWith :: Monad m => s -> (forall r. (r, s) -> (r -> b -> EitherT (r, s) m (r, s)) -> a -> EitherT (r, s) m (r, s)) -> Conduit a m b Source #
Most of the time conduits pass the fold variable through unmolested, but
sometimes you need to ignore that variable and use your own within a
stage of the pipeline. This is done by wrapping the fold variable in a
tuple and then unwrapping it when the conduit is done. conduitWith
makes this transparent.
awaitForever :: (a -> Source m b) -> Conduit a m b Source #
sourceList :: Monad m => [a] -> Source m a Source #
sourceLazy :: (Monad m, LazySequence lazy strict) => lazy -> Source m strict Source #
sourceHandle :: forall m a. (MonadIO m, MonoFoldable a, IOData a) => Handle -> Source m a Source #
sourceFile :: (MonadBaseControl IO m, MonadIO m, MonoFoldable a, IOData a) => FilePath -> Source m a Source #
sourceIOHandle :: (MonadBaseControl IO m, MonadIO m, MonoFoldable a, IOData a) => IO Handle -> Source m a Source #
stdinC :: (MonadBaseControl IO m, MonadIO m, MonoFoldable a, IOData a) => Source m a Source #
initRepeat :: Monad m => m seed -> (seed -> m a) -> Source m a Source #
sourceRandomGen :: (Variate a, MonadBase base m, PrimMonad base) => Gen (PrimState base) -> Source m a Source #
sourceRandomNGen :: (Variate a, MonadBase base m, PrimMonad base) => Gen (PrimState base) -> Int -> Source m a Source #
sourceDirectory :: forall m. MonadBaseControl IO m => FilePath -> Source m FilePath Source #
sourceDirectoryDeep :: forall m. MonadBaseControl IO m => Bool -> FilePath -> Source m FilePath Source #
dropWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> Conduit seq m seq Source #
foldCE :: (Monad m, MonoFoldable mono, Monoid (Element mono)) => Sink mono m (Element mono) Source #
foldMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> Sink mono m w Source #
notElemCE :: (Monad m, MonoFoldable seq, Eq (Element seq)) => Element seq -> Sink seq m Bool Source #
sinkLazyBuilder :: (Monad m, Monoid builder, ToBuilder a builder, Builder builder lazy) => Sink a m lazy Source #
awaitNonNull :: (Monad m, MonoFoldable a) => Conduit a m (Maybe (NonNull a)) Source #
lengthIfCE :: (Monad m, Num len, MonoFoldable mono) => (Element mono -> Bool) -> Sink mono m len Source #
productCE :: (Monad m, MonoFoldable mono, Num (Element mono)) => Sink mono m (Element mono) Source #
foldMCE :: (Monad m, MonoFoldable mono) => (a -> Element mono -> m a) -> a -> Sink mono m a Source #
foldMapMCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> m w) -> Sink mono m w Source #
sinkIOHandle :: (MonadBaseControl IO m, MonadIO m, IOData a) => IO Handle -> Sink a m () Source #
omapCE :: (Monad m, MonoFunctor mono) => (Element mono -> Element mono) -> Conduit mono m mono Source #
concatMapC :: (Monad m, MonoFoldable mono) => (a -> mono) -> Conduit a m (Element mono) Source #
concatMapCE :: (Monad m, MonoFoldable mono, Monoid w) => (Element mono -> w) -> Conduit mono m w Source #
takeWhileC :: Monad m => (a -> Bool) -> Conduit a m a Source #
This function reads one more element than it yields, which would be a problem if Sinks were monadic, as they are in conduit or pipes. There is no such concept as "resuming where the last conduit left off" in this library.
takeWhileCE :: (Monad m, IsSequence seq) => (Element seq -> Bool) -> Conduit seq m seq Source #
takeExactlyCE :: (Monad m, IsSequence a) => Index a -> Conduit a m b -> Conduit a m b Source #
conduitVector :: (MonadBase base m, Vector v a, PrimMonad base) => Int -> Conduit a m (v a) Source #
Collect elements into a vector until the size maxSize
is reached, then
yield that vector downstream.
concatMapAccumC :: Monad m => (a -> accum -> (accum, [b])) -> accum -> Conduit a m b Source #
encodeBase64C :: Monad m => Conduit ByteString m ByteString Source #
decodeBase64C :: Monad m => Conduit ByteString m ByteString Source #
encodeBase64URLC :: Monad m => Conduit ByteString m ByteString Source #
decodeBase64URLC :: Monad m => Conduit ByteString m ByteString Source #
encodeBase16C :: Monad m => Conduit ByteString m ByteString Source #
decodeBase16C :: Monad m => Conduit ByteString m ByteString Source #
omapMCE :: (Monad m, MonoTraversable mono) => (Element mono -> m (Element mono)) -> Conduit mono m mono Source #
concatMapMC :: (Monad m, MonoFoldable mono) => (a -> m mono) -> Conduit a m (Element mono) Source #
concatMapAccumMC :: Monad m => (a -> accum -> m (accum, [b])) -> accum -> Conduit a m b Source #
encodeUtf8C :: Monad m => Conduit Text m ByteString Source #
decodeUtf8C :: MonadThrow m => Conduit ByteString m Text Source #
lineC :: (Monad m, IsSequence seq, Element seq ~ Char) => Conduit seq m o -> Conduit seq m o Source #
lineAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => Conduit seq m o -> Conduit seq m o Source #
unlinesAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8) => Conduit seq m seq Source #
linesUnboundedC_ :: forall m seq. (Monad m, IsSequence seq, Eq (Element seq), Semigroup seq) => Element seq -> Conduit seq m seq Source #
linesUnboundedC :: (Monad m, IsSequence seq, Element seq ~ Char, Semigroup seq) => Conduit seq m seq Source #
linesC :: (Monad m, IsSequence seq, Element seq ~ Char, Semigroup seq) => Conduit seq m seq Source #
linesUnboundedAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8, Semigroup seq) => Conduit seq m seq Source #
linesAsciiC :: (Monad m, IsSequence seq, Element seq ~ Word8, Semigroup seq) => Conduit seq m seq Source #
sourceMaybeMVar :: forall m a. MonadIO m => MVar (Maybe a) -> Source m a Source #
Keep taking from an MVar (Maybe a)
until it yields Nothing
.
sourceMaybeTMVar :: forall a. TMVar (Maybe a) -> Source STM a Source #
Keep taking from an TMVar (Maybe a)
until it yields Nothing
.
sourceTChan :: forall a. TChan a -> Source STM a Source #
A Source for exhausting a TChan, but blocks if it is initially empty.
zipSinks :: forall a m r r'. (MonadBaseControl IO m, MonadIO m) => Sink a m r -> Sink a m r' -> Sink a m (r, r') Source #
(=$=) :: (a -> b) -> (b -> c) -> a -> c infixr 2 Source #
Compose two Conduit
. This is also just function composition.
sequenceSources :: (Traversable f, Monad m) => f (Source m a) -> Source m (f a) Source #
Sequence a collection of sources.
>>>
sinkList $ sequenceSources [yieldOne 1, yieldOne 2, yieldOne 3]
[[1,2,3]]