@@ -49,7 +49,7 @@ import Control.Monad.Class.MonadFork
49
49
import Control.Monad.Class.MonadThrow
50
50
import Control.Tracer (Tracer (.. ), contramap , traceWith )
51
51
import Data.Functor.Identity (Identity (.. ))
52
- import Data.Maybe (fromMaybe )
52
+ import Data.Maybe (maybeToList )
53
53
54
54
55
55
-- $intro
@@ -326,13 +326,16 @@ runAnnotatedDecoderWithChannel
326
326
-> DecodeStep bytes failure m (bytes -> a )
327
327
-> m (Either failure (a , Maybe bytes ))
328
328
329
- runAnnotatedDecoderWithChannel Channel {recv} bs0 = go (fromMaybe mempty bs0) bs0
329
+ runAnnotatedDecoderWithChannel Channel {recv} bs0 = go (maybeToList bs0) bs0
330
330
where
331
- go :: bytes -> Maybe bytes -> DecodeStep bytes failure m (bytes -> a ) -> m (Either failure (a , Maybe bytes ))
332
- go bytes _ (DecodeDone f trailing) = return $ Right (f bytes, trailing)
333
- go _bytes _ (DecodeFail failure) = return (Left failure)
334
- go bytes Nothing (DecodePartial k) = recv >>= \ bs -> k bs >>= go (bytes <> fromMaybe mempty bs) Nothing
335
- go bytes (Just trailing) (DecodePartial k) = k (Just trailing) >>= go (bytes <> trailing) Nothing
331
+ go :: [bytes ]
332
+ -> Maybe bytes
333
+ -> DecodeStep bytes failure m (bytes -> a )
334
+ -> m (Either failure (a , Maybe bytes ))
335
+ go ! bytes _ (DecodeDone f trailing) = return $ Right (f $ mconcat (reverse bytes), trailing)
336
+ go _bytes _ (DecodeFail failure) = return (Left failure)
337
+ go ! bytes Nothing (DecodePartial k) = recv >>= \ bs -> k bs >>= go (maybe bytes (: bytes) bs) Nothing
338
+ go ! bytes (Just trailing) (DecodePartial k) = k (Just trailing) >>= go (trailing : bytes) Nothing
336
339
337
340
338
341
data Role = Client | Server
0 commit comments