handleToMDHs :: Handle -> IO (Either P.DecodingError (P.Producer P.ByteString IO ()))
handleToMDHs h = do
hLen <- P.evalStateT (P.decodeGet getWord32le) (PB.fromHandle h)
case (hLen :: Either P.DecodingError Word32) of
Left err -> return $ Left err
Right len -> fmap Right (skipAndProceed h len)
where
skipAndProceed :: Handle -> Word32 -> IO (P.Producer P.ByteString IO ())
skipAndProceed handle l = do
(hSeek handle AbsoluteSeek) (fromIntegral l)
return $ PB.fromHandle handle
handleToMDHs :: Handle -> IO (Either P.DecodingError (P.Producer MDH IO ()))
type ErrorResultProducer = P.Producer MDHAndScanLine IO (Either
(P.DecodingError, P.Producer P.ByteString IO ()) ())
measDatMDHScanLinePairs :: Handle ->
IO (Either P.DecodingError ErrorResultProducer)
measDatMDHScanLinePairs h = do
hLen <- P.evalStateT (P.decodeGet getWord32le) (PB.fromHandle h)
case (hLen :: Either P.DecodingError Word32) of
Left err -> return $ Left err
Right len -> fmap Right (skipAndProceed h len)
where
skipAndProceed :: Handle -> Word32 -> IO ErrorResultProducer
skipAndProceed handle l = do
(hSeek handle AbsoluteSeek) (fromIntegral l)
return $ mdhProd (PB.fromHandle handle)
mdhProd :: P.Producer P.ByteString IO () -> ErrorResultProducer
mdhProd bsProd = view P.decoded bsProd
--
You received this message because you are subscribed to the Google Groups "Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-pipe...@googlegroups.com.
To post to this group, send email to haskel...@googlegroups.com.
Pipes.Group.folds :: Monad m => (x -> a -> x) -- ^ Step function -> x -- ^ Initial accumulator -> (x -> b) -- ^ Extraction function -> FreeT (Producer a m) m r -- ^ -> Producer b m r
If I'm reading this right, when my FreeT "list" consists of just one Producer, then Pipes.Groups.folds returns a Producer that yields one output, and preserves the original Producer's return type, r, in the returned Producer. This is in contrast to the similar functionPipes.Prelude.fold :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Producer a m () -> m b
which only works on Producers with return type (). You note in the documentation for Pipes.Prelude.fold that this type is required because it may stop drawing from the Producer early, so you don't necessarily get to compute the return type. I'm wondering if it's easy to define a function:: Monad m =>
(x -> b -> x)
-> x -> (x -> b) -> Producer a m r -> Producer b m r -- specializing a bit
But it seems you want to fold, but then yield the single result. (This is effectively what folds is doing, repeatedly for each of the successive producers in
a FreeT (Producer a m) m r. But the simple case is pretty straightforward with the asterisked fold' in Pipes.Prelude:
P.fold'
:: Monad m =>
(x -> a -> x) -> x -> (x -> b) -> Producer a m r -> m (b, r)
foldToProducer
:: Monad m => (x -> a -> x) -> x -> (x -> b) -> Producer a m r -> Producer b m r
foldToProducer op seed out p = do
(b,r) <- lift $ P.fold' op seed out p
yield b
return r
I don't know if there would be a swanker way of doing it just with standard combinators. But is that more like what you mean?
\op seed out -> folds op seed out . elevate
:: Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Producer a m r -> Producer b m r
as you planned.
groupByID :: Monad m => P.Producer MDHAndScanLine m (Either String ()) ->P.FreeT (P.Producer MDHAndScanLine m) m (Either String ())
example: :: Monad m => P.FreeT (P.Producer MDHAndScanLine m) m (Either String ()) ->
P.Producer GroupedMDHs m (Either String ())
groupedMDHParser :: Monad m => Int -> P.Parser MDHAndScanLine m (Either (Either String ()) GroupedMDHs)
example groupedMDHScanLines = P.concats $ P.maps (\p -> p >-> groupedMDHParser) groupedMDHScanLines
...
...
...
...
--
newtype Fallible m r i e = Fallible { getFallible :: FoldM (ExceptT e m) i r }
...