From 61fca70a5e099f378a06f23096b54a4fbbb299a2 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sun, 21 Nov 2021 02:22:40 -0500 Subject: [PATCH] refactored readLoop --- src/Network/Gemini/Capsule/Internal.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Network/Gemini/Capsule/Internal.hs b/src/Network/Gemini/Capsule/Internal.hs index 088d694..1c0e1bd 100644 --- a/src/Network/Gemini/Capsule/Internal.hs +++ b/src/Network/Gemini/Capsule/Internal.hs @@ -40,6 +40,7 @@ module Network.Gemini.Capsule.Internal ( stripCRLF ) where +import Control.Monad (when) import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Maybe (MaybeT (..)) import qualified Data.ByteString as BS @@ -119,9 +120,10 @@ readLoop :: Int -> S.InputStream BS.ByteString -> MaybeT IO Builder readLoop maxLen src = lift (S.read src) >>= \case Nothing -> return mempty - Just bs -> let len = BS.length bs in - if len > maxLen - then MaybeT $ return Nothing - else (byteString bs <>) <$> readLoop (maxLen - len) src + Just bs -> do + let len = BS.length bs + when (len > maxLen) $ + MaybeT $ return Nothing + (byteString bs <>) <$> readLoop (maxLen - len) src --jl