lines package:rio

Splits the argument into a list of lines stripped of their terminating \n characters. The \n terminator is optional in a final non-empty line of the argument string. When the argument string is empty, or ends in a \n character, it can be recovered by passing the result of lines to the unlines function. Otherwise, unlines appends the missing terminating \n. This makes unlines . lines idempotent:
(unlines . lines) . (unlines . lines) = (unlines . lines)

Examples

>>> lines ""           -- empty input contains no lines
[]
>>> lines "\n"         -- single empty line
[""]
>>> lines "one"        -- single unterminated line
["one"]
>>> lines "one\n"      -- single non-empty line
["one"]
>>> lines "one\n\n"    -- second line is empty
["one",""]
>>> lines "one\ntwo"   -- second line is unterminated
["one","two"]
>>> lines "one\ntwo\n" -- two non-empty lines
["one","two"]
O(n) Breaks a Text up into a list of Texts at newline characters '\n' (LF, line feed). The resulting strings do not contain newlines. lines does not treat '\r' (CR, carriage return) as a newline character.
linesCR breaks a String up into a list of Strings at newline Chars. It is very similar to lines, but it also removes any trailing 'r' Chars. The resulting String values do not contain newlines or trailing 'r' characters.
linesCR breaks a Text up into a list of Texts at newline Chars. It is very similar to lines, but it also removes any trailing 'r' characters. The resulting Text values do not contain newlines or trailing 'r' characters.
Zl: Separator, Line
Appends a \n character to each input string, then concatenates the results. Equivalent to foldMap (s -> s ++ "\n").

Examples

>>> unlines ["Hello", "World", "!"]
"Hello\nWorld\n!\n"
Note that unlines . lines /= id when the input is not \n-terminated:
>>> unlines . lines $ "foo\nbar"
"foo\nbar\n"
O(n) Joins lines, after appending a terminating newline to each.