Skip to content

Instantly share code, notes, and snippets.

@adamConnerSax
Created October 29, 2021 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamConnerSax/f115bb26a15e597d1199d42af2645568 to your computer and use it in GitHub Desktop.
Save adamConnerSax/f115bb26a15e597d1199d42af2645568 to your computer and use it in GitHub Desktop.
unfoldViaBS' :: Applicative m => Streamly.Unfold.Unfold m BL.ByteString BL.ByteString
unfoldViaBS' = Streamly.Unfold.unfoldr inner
where
{-# INLINE inner #-}
inner input'
| BL.null input' = Nothing
| otherwise =
case BL.elemIndex _lf input' of
Nothing -> Just (input', BL.empty)
Just i ->
let (prefix, suffix) = BL.splitAt i input'
in Just (prefix, BL.drop 1 suffix)
{-# INLINE unfoldViaBS' #-}
unfoldViaBS :: MonadIO m => Streamly.Unfold.Unfold m IO.Handle Text
unfoldViaBS = fmap (Text.decodeUtf8 . BL.toStrict) $ Streamly.Unfold.lmapM (liftIO . BL.hGetContents) unfoldViaBS'
{-# INLINE unfoldViaBS #-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment