Append the given Doc to this one, separated by a space.
Append the given String to this Doc, separated by a space.
Append the given String to this Doc, separated by a space.
The expression str &: d
is equivalent to Doc.text(str) & d
.
Synonym for .
Synonym for .repeat. If n > 0 repeat the doc n times, else return empty
Append the given Doc to this one.
Prepend the given String to this Doc.
Prepend the given String to this Doc.
The expression str +: d
is equivalent to Doc.text(str) + d
.
Append the given Doc to this one, separated by a newline.
Prepend the given String to this Doc, separated by a newline.
Prepend the given String to this Doc, separated by a newline.
The expression str /: d
is equivalent to Doc.text(str) / d
.
Append the given String to this Doc, separated by a space.
Append the given String to this Doc, separated by a space.
The expression d :& str
is equivalent to d & Doc.text(str)
.
Append the given String to this Doc.
Append the given String to this Doc.
The expression d :+ str
is equivalent to d + Doc.text(str)
.
Append the given String to this Doc, separated by a newline.
Append the given String to this Doc, separated by a newline.
The expression d :/ str
is equivalent to d / Doc.text(str)
.
aligned sets the nesting to the column position before we render the current doc.
aligned sets the nesting to the column position before we render the current doc. This is useful if you have:
Doc.text("foo") + (Doc.text("bar").line(Doc.text("baz"))).align
which will render as:
foobar baz
Bookend this Doc between the given Docs.
Bookend this Doc between the given Docs.
If the documents (when flattened) all fit on one line, then newlines will be collapsed, spaces will be added, and the document will render on one line. If you do not want a space, see tightBracketBy
Otherwise, newlines will be used on either side of this document, and the requested level of indentation will be added as well.
Convert this Doc to a single-line representation.
Convert this Doc to a single-line representation.
All newlines are replaced with spaces (and optional indentation is ignored). The resulting Doc will never render any newlines, no matter what width is used.
This method is similar to flatten, but returns None if no flattening was needed (i.
This method is similar to flatten, but returns None if no flattening was needed (i.e. if no newlines or unions were present).
As with flatten, the resulting Doc (if any) will never render any newlines, no matter what width is used.
Treat this Doc as a group that can be compressed.
Treat this Doc as a group that can be compressed.
The effect of this is to replace newlines with spaces, if there is enough room. Otherwise, the Doc will be rendered as-is.
Compute a hash code for this Doc.
Compute a hash code for this Doc.
Returns true if all renders return the empty string
Append the given String to this one, separated by a newline.
Append the given Doc to this one, separated by a newline.
Append the given String to this Doc, using a space (if there is enough room), or a newline otherwise.
Append the given Doc to this one, using a space (if there is enough room), or a newline otherwise.
Returns the largest width which may affect how this Doc renders.
Returns the largest width which may affect how this Doc renders. All widths larger than this amount are guaranteed to render the same.
Note that this does not guarantee that all widths below this value are distinct, just that they may be distinct. This value is an upper-bound on widths that produce distinct renderings, but not a least upper-bound.
Nest appends spaces to any newlines occurring within this Doc.
Nest appends spaces to any newlines occurring within this Doc.
The effect of this is cumulative. For example, the expression
x.nested(1).nested(2)
is equivalent to x.nested(3)
.
d.
d.nonEmpty == !d.isEmpty
Render this Doc as a String, limiting line lengths to width
or
shorter when possible.
Render this Doc as a String, limiting line lengths to width
or
shorter when possible.
Note that this method does not guarantee there are no lines
longer than width
-- it just attempts to keep lines within this
length when possible.
Render this Doc as a stream of strings, treating width
in the
same way as render
does.
Render this Doc as a stream of strings, treating width
in the
same way as render
does.
The expression d.renderStream(w).mkString
is equivalent to
d.render(w)
.
Render this Doc as a stream of strings, treating width
in the
same way as render
does.
Render this Doc as a stream of strings, treating width
in the
same way as render
does.
The expression d.renderStream(w).mkString
is equivalent to
d.render(w)
.
Lines consisting of only indentation are represented by the empty string.
Render this Doc as a String, limiting line lengths to width
or
shorter when possible.
Render this Doc as a String, limiting line lengths to width
or
shorter when possible.
Note that this method does not guarantee there are no lines
longer than width
-- it just attempts to keep lines within this
length when possible.
Lines consisting of only indentation are represented by the empty string.
Render this Doc as a stream of strings, using the widest possible variant.
Render this Doc as a stream of strings, using the widest possible variant. This is the same as render(Int.MaxValue) except it is more efficient.
If n > 0, repeat the Doc that many times, else return empty
Produce a verbose string representation of this Doc.
Produce a verbose string representation of this Doc.
Unlike render
, this method will reveal the internal tree
structure of the Doc (i.e. how concatenation and union nodes are
constructed), as well as the contents of every text node.
By default, only the left side of union nodes is displayed. If
forceUnions = true
is passed, then both sides of the union are
rendered (making this potentially-expensive method even more
expensive).
Append the given String to this Doc, separated by a space.
Append the given Doc to this one, separated by a space.
Bookend this Doc between the given Docs.
Bookend this Doc between the given Docs.
If the documents (when flattened) all fit on one line, then newlines will be collapsed, without a space and the document will render on one line. If you want the newline to collapse to a space, see bracketBy.
Otherwise, newlines will be used on either side of this document, and the requested level of indentation will be added as well.
Return a very terse string for this Doc.
Return a very terse string for this Doc.
To get a full representation of the document's internal
structure, see verboseString
.
Render this Doc at the given width
, and write it to the given
PrintWriter.
Render this Doc at the given width
, and write it to the given
PrintWriter.
The expression x.writeTo(w, pw)
is equivalent to
pw.print(x.render(w))
, but will usually be much more efficient.
This method does not close pw
or have any side-effects other
than the actual writing.
Render this Doc at the given width
, and write it to the given
PrintWriter.
Render this Doc at the given width
, and write it to the given
PrintWriter.
The expression x.writeTo(w, pw)
is equivalent to
pw.print(x.render(w))
, but will usually be much more efficient.
This method does not close pw
or have any side-effects other
than the actual writing.
Lines consisting only of indentation are represented by the empty string.
implementation of Wadler's classic "A Prettier Printer"
http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf