I was wondering what the preferred method is to convert lazy text into a list of strict texts split up by line endings. I came up with something like the following, but am not sure that I’m guaranteed that each strict text element will be a complete line (or if there are other problems with it):
import qualified Data.Text.Lazy as LT
readLines filePath = do
contents <- Data.Text.Lazy.IO.readFile filePath
let lines = concat (map LT.toChunks (LT.lines contents))
return lines
doesn’t guarantee that each strict chunk is a complete line. In fact, every time a chunk boundary of the lazy
Textdoes not coincide with a line boundary, you get a line having part in at least two strict chunks.however, concatenates each line into one strict chunk. Doing the concatenation may however be slower than working with each line as a list of strict chunks resp. a lazy
Text.