Last active
August 27, 2019 21:05
-
-
Save qnikst/5a436ac4f22b47b24fba7f73e1a64d49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Binary | |
import Data.Binary.Get | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Lazy as BL | |
stream :: Binary a => BL.ByteString -> [a] | |
stream = go (runGetIncremental get) . BL.toChunks where | |
go (Done rest _ a) [] | |
| B.null rest = [a] | |
| otherwise = a:go (runGetIncremental get `pushChunk` rest) [] | |
go (Done rest _ a) (x:xs) | |
| B.null rest = a:go (runGetIncremental get `pushChunk` x) xs | |
| otherwise = a:go (runGetIncremental get ` pushChunk` rest) (x:xs) | |
go (Partial f) [] = go (f Nothing) [] | |
go (Partial f) (x:xs) = go (f (Just x)) xs | |
go (Fail _ _ s) _ = error s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment