I have a function that takes a lazy ByteString
, that I wish to have return lists of strict ByteStrings
(the laziness should be transferred to the list type of the output).
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
csVals :: L.ByteString -> [B.ByteString]
I want to do this for various reasons, several lexing functions require strict ByteString
s, and I can guarantee the outputted strict ByteString
s in the output of csVal
s above are very small.
How do I go about "strictifying" ByteString
s without chunking them?
Update0
I want to take a Lazy ByteString
, and make one strict ByteString
containing all its data.
toChunks
? From the initial glimpse it looks like it preserves laziness. – SentineltoChunks
exposes that structure. To put the list all in one strict bytestring, there's no other way thanconcat . toChunks
(or the equiv). In many typical cases, the list will have a single element -- in those casesconcat . toChunks
will be relatively efficient as well. – Benignity