unlines -package:streamly-core
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"
unlines joins lines, appending a terminating newline after
each.
Equivalent to
concat . Data.List.concatMap (\x -> [x,
singleton '\n']).
O(n) Joins lines, after appending a terminating newline to
each.
Insert a newline character after each incoming chunk of data.
Subject to fusion
Appends a
\n character to each input string, then
concatenates the results. Equivalent to
foldMap (s ->
s ++ "\n").
>>> 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"
unlines takes list of
Text values and joins them with
line separator.
Actual type of this function is the following:
unlines :: [Text] -> Text
but it was given a more complex type to provide friendlier compile
time errors.
>>> unlines []
""
>>> unlines ["line 1"]
"line 1\n"
>>> unlines ["first line", "second line"]
"first line\nsecond line\n"
>>> unlines (["line 1", "line 2"] :: [String])
...
... 'unlines' works with 'Text', not 'String'.
Possible fixes:
1. Make sure OverloadedStrings extension is enabled.
2. Apply 'toText' to a single value.
3. Apply 'map toText' to the list value.
...
>>> unlines [True, False]
...
... 'unlines' works with 'Text'
But given: 'Bool'
...
unlines is an inverse operation to
lines. It joins
lines, after appending a terminating newline to each.
>>> unlines ["Hello", "World", "!"]
"Hello\nWorld\n!\n"
Join a list of textual sequences using newlines.
> unlines ["abc","def","ghi"]
"abc\ndef\nghi"
Improper lens between lines and a bytestream
Note: This function is purely for demonstration purposes since it
assumes a particular encoding. You should prefer the
Text
equivalent of this function from the
pipes-text library.
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.
O(n) Joins lines, after appending a terminating newline to
each.
Joins up lines by a newline character. It does not leave a newline
after the last line. If you want a more classical
unlines
behaviour, use
map along with
snoc.
Concatenate documents after appending a terminating newline symbol to
each.
unlines [] == mempty
unlines [mempty] == "\n"
unlines ["title", "subtitle"] == "title\nsubtitle\n"
The
unlines function is an inverse operation to
lines.
It joins lines, after appending a terminating newline to each.
Concatenate lines together with
\n.
In contrast to their counterparts from
Data.List, it holds that
unlines . lines = id.
List version of
$$.
Note that:
unlines = foldr ($$) mempty
Appends a
n character to each input string, then concatenates
the results. Equivalent to
foldMap (s -> s ++
"n").
>>> unlines ["Hello", "World", "!"]
"Hello\nWorld\n!\n"
Note
unlines . lines /= id when
the input is not
n-terminated:
>>> unlines . lines $ "foo\nbar"
"foo\nbar\n"
Combine multiple lines with line break. Type-level version of the
unlines function but for ErrorMessage.
Like
unlines, but does not append a trailing newline if there
is at least one line. For example:
unlinesConcise ["A", "B"] == "A\nB"
unlinesConcise [] == ""
Whereas:
unlines ["A", "B"] == "A\nB\n"
unlines [] == ""
This is closer to the behaviour of
unwords, which does not
append a trailing space.
Same as unlines, but operates on ASCII/binary data.
Insert a newline character after each incoming chunk of data.