lines package:streaming-bytestring

lines turns a ByteStream into a connected stream of ByteStreams at divide at newline characters. The resulting strings do not contain newlines. This is the genuinely streaming lines which only breaks chunks, and thus never increases the use of memory. Because ByteStreams are usually read in binary mode, with no line ending conversion, this function recognizes both \n and \r\n endings (regardless of the current platform).
lineSplit turns a ByteStream into a connected stream of ByteStreams at divide after a fixed number of newline characters. Unlike most of the string splitting functions in this library, this function preserves newlines characters. Like lines, this function properly handles both \n and \r\n endings regardless of the current platform. It does not support \r or \n\r line endings.
>>> let planets = ["Mercury","Venus","Earth","Mars","Saturn","Jupiter","Neptune","Uranus"]

>>> S.mapsM_ (\x -> putStrLn "Chunk" >> Q.putStrLn x) $ Q.lineSplit 3 $ Q.string $ L.unlines planets
Chunk
Mercury
Venus
Earth
Chunk Mars Saturn Jupiter Chunk Neptune Uranus Since all characters originally present in the stream are preserved, this function satisfies the following law:
Ɐ n bs. concat (lineSplit n bs) ≅ bs
The unlines function restores line breaks between layers. Note that this is not a perfect inverse of lines:
  • lines . unlines can produce more strings than there were if some of the "lines" had embedded newlines.
  • unlines . lines will replace \r\n with \n.