Safe Haskell | None |
---|---|
Language | Haskell98 |
- data Fold1 b e a
- fold1 :: Fold1 b Void a -> Producer b IO r -> IO (a, r)
- fold1Fallibly :: Fold1 b e a -> Producer b IO r -> IO (Either e (a, r))
- withFold :: Fold b a -> Fold1 b e a
- withFoldIO :: FoldM IO b a -> Fold1 b e a
- withFallibleFold :: FoldM (ExceptT e IO) b a -> Fold1 b e a
- withConsumer :: Consumer b IO () -> Fold1 b e ()
- withConsumer' :: Consumer b IO Void -> Fold1 b e ()
- withConsumerM :: MonadIO m => (m () -> IO (Either e a)) -> Consumer b m () -> Fold1 b e a
- withConsumerM' :: MonadIO m => (forall r. m r -> IO (Either e (a, r))) -> Consumer b m Void -> Fold1 b e a
- withSafeConsumer :: Consumer b (SafeT IO) Void -> Fold1 b e ()
- withFallibleConsumer :: Consumer b (ExceptT e IO) Void -> Fold1 b e ()
- withParser :: Parser b IO (Either e a) -> Fold1 b e a
- withParserM :: MonadIO m => (forall r. m (a, r) -> IO (Either e (c, r))) -> Parser b m a -> Fold1 b e c
- withCont :: (Producer b IO () -> IO a) -> Fold1 b e a
- withCont' :: (forall r. Producer b IO r -> IO (a, r)) -> Fold1 b e a
- withFallibleCont :: (Producer b IO () -> IO (Either e a)) -> Fold1 b e a
- withFallibleCont' :: (forall r. Producer b IO r -> IO (Either e (a, r))) -> Fold1 b e a
- data Transducer x b e a
- data Delimited
- data Continuous
- transduce1 :: Transducer Continuous b e a -> Fold1 a e r -> Fold1 b e r
- mapper :: (a -> b) -> Transducer Continuous a e b
- fallibleMapper :: (a -> Either e b) -> Transducer Continuous a e b
- mapperFoldable :: Foldable f => (a -> f b) -> Transducer Continuous a e b
- mapperEnumerable :: Enumerable f => (a -> f IO b) -> Transducer Continuous a e b
- transducer :: (forall r. Producer b IO r -> Producer a IO r) -> Transducer Continuous b e a
- fallibleTransducer :: (forall r. Producer b IO r -> Producer a IO (Either e r)) -> Transducer Continuous b e a
- delimit :: (forall r. Producer a IO r -> FreeT (Producer a' IO) IO r) -> Transducer Continuous b e a -> Transducer Delimited b e a'
- groups :: (forall r. Producer b IO r -> Producer b' IO r) -> Transducer Delimited a e b -> Transducer Delimited a e b'
- folds :: Fold1 b Void b' -> Transducer Delimited a e b -> Transducer Continuous a e b'
- concats :: Transducer Delimited a e b -> Transducer Continuous a e b
- intercalates :: Producer b IO () -> Transducer Delimited a e b -> Transducer Continuous a e b
- data Fold2 b1 b2 e a
- fold2 :: Fold2 b1 b2 Void a -> Producer b1 IO r1 -> Producer b2 IO r2 -> IO (a, r1, r2)
- fold2Fallibly :: Fold2 b1 b2 e a -> Producer b1 IO r1 -> Producer b2 IO r2 -> IO (Either e (a, r1, r2))
- liftFirst :: Fold1 b1 e r1 -> Fold2 b1 b2 e r1
- liftSecond :: Fold1 b2 e r1 -> Fold2 b1 b2 e r1
- separated :: Fold1 b1 e r1 -> Fold1 b2 e r2 -> Fold2 b1 b2 e (r1, r2)
- combined :: Transducer Delimited b1 e x -> Transducer Delimited b2 e x -> Fold1 x e a -> Fold2 b1 b2 e a
- trip :: Fold1 b b ()
- tripx :: Fold1 b e ()
Producer folds
A computation in IO
that completely drains a Producer
of b
values,
returning a value of type a
, except when it fails early with an error of
type e
.
Bifunctor (Fold1 b) Source |
|
Functor (Fold1 b e) Source | |
Applicative (Fold1 b e) Source |
|
Monoid a => Monoid (Fold1 b e a) Source |
fold1 :: Fold1 b Void a -> Producer b IO r -> IO (a, r) Source
Run a Fold1
that never returns an error value (but which may still throw exceptions!)
Building producer folds
From foldl folds
Fold1
values can be created out of the more general folds of the foldl
library, which are producer-agnostic.
withFoldIO :: FoldM IO b a -> Fold1 b e a Source
withFallibleFold :: FoldM (ExceptT e IO) b a -> Fold1 b e a Source
From consumers
Fold1
values can be created out of Consumer
s from the pipes
library.
withConsumer :: Consumer b IO () -> Fold1 b e () Source
withConsumer' :: Consumer b IO Void -> Fold1 b e () Source
Builds a Fold1
out of a Consumer
that never stops by itself.
From parsers
Fold1
values can be created out of Parser
s from the pipes-parse
library.
From continuations
The most general way of constructing Fold1
values is from an arbitrary
function that consumes a Producer
.
Fold transducers
data Transducer x b e a Source
A transformation that takes the inputs of a Fold1
from type a
to type b
.
Optionally, the transformation may delimit groups of elements in the
stream. In that case the phantom type x
will be Delimited
. Otherwise, it will be
Continuous
.
Bifunctor (Transducer x b) Source | |
Functor (Transducer x b e) Source |
data Continuous Source
transduce1 :: Transducer Continuous b e a -> Fold1 a e r -> Fold1 b e r Source
Apply a Transducer
to a Fold1
.
Building fold transducers
:: (a -> b) | |
-> Transducer Continuous a e b |
:: (a -> Either e b) | |
-> Transducer Continuous a e b |
:: Foldable f | |
=> (a -> f b) | |
-> Transducer Continuous a e b |
:: Enumerable f | |
=> (a -> f IO b) | |
-> Transducer Continuous a e b |
:: (forall r. Producer b IO r -> Producer a IO r) | |
-> Transducer Continuous b e a |
:: (forall r. Producer b IO r -> Producer a IO (Either e r)) | |
-> Transducer Continuous b e a |
Transducer group operations
:: (forall r. Producer a IO r -> FreeT (Producer a' IO) IO r) | |
-> Transducer Continuous b e a | |
-> Transducer Delimited b e a' |
Plug splitting functions from pipes-group
here.
:: (forall r. Producer b IO r -> Producer b' IO r) | |
-> Transducer Delimited a e b | |
-> Transducer Delimited a e b' |
Tweak each of the groups delimited by a Transducer
.
:: Fold1 b Void b' | |
-> Transducer Delimited a e b | |
-> Transducer Continuous a e b' |
:: Transducer Delimited a e b | |
-> Transducer Continuous a e b |
:: Producer b IO () | |
-> Transducer Delimited a e b | |
-> Transducer Continuous a e b |
Multiple producer folds
A computation in IO
that completely drains two Producer
s of b
values
in a concurrent way, returning a value of type a
, except when it fails early
with an error of type e
.
fold2 :: Fold2 b1 b2 Void a -> Producer b1 IO r1 -> Producer b2 IO r2 -> IO (a, r1, r2) Source
Run a Fold2
that never returns an error value (but which may still throw exceptions!)
fold2Fallibly :: Fold2 b1 b2 e a -> Producer b1 IO r1 -> Producer b2 IO r2 -> IO (Either e (a, r1, r2)) Source
Run a Fold2
.
Building multiple producer folds
liftSecond :: Fold1 b2 e r1 -> Fold2 b1 b2 e r1 Source
separated :: Fold1 b1 e r1 -> Fold1 b2 e r2 -> Fold2 b1 b2 e (r1, r2) Source
Consume the producers concurrently, each one independently of the other.
combined :: Transducer Delimited b1 e x -> Transducer Delimited b2 e x -> Fold1 x e a -> Fold2 b1 b2 e a Source
Consume the producers concurrently, delimiting groups in each producer,
and writing the groups into a common Fold1
.
Possible use: find lines in two text producers and combine the lines in a single stream, preserving the integrity of each individual line.
Utilities
Fail if the Producer
produces anything at all. The error value is what came
out of the Producer
.
>>>
fold1Fallibly trip (mapM_ yield ['z'])
Left 'z'
>>>
fold1Fallibly trip (mapM_ yield [])
Right ((),())
Throw an exception if the Producer
produces anything at all
BEWARE!
This 'Transducer may throw AssertionFailed
.
BEWARE!
>>>
fold1Fallibly tripx (mapM_ yield ['z'])
*** Exception: tripx