joined

fun List<PrettyPrintable>.joined(separator: PrettyPrintable = Document(","), prefix: PrettyPrintable = Document(), postfix: PrettyPrintable = Document()): Document

Concatenates all the elements separated by separator and enclosed in prefix and postfix.

The elements are laid out horizontally if that fits the page (note the extra space after separators):

val docs = listOf("1", "2", "3", "4").map { Document(it) }
>>> docs.joined(separator = Document(","), prefix = Document("("), postfix = Document(")"))
(1, 2, 3, 4)

If there is not enough space, the input is split into lines entry-wise with separators at the end:

>>> docs.joined(separator = Document(","), prefix = Document("("), postfix = Document(")"))
(
1,
2,
3,
4)

Use nested to add indentation when the elements are split across lines.