liveBook · Manning

ConcatDoc

As explained in Fabulous Adventures in Data Structures and Algorithms

ConcatDoc is the book's Doc variant that combines left and right child documents in output order.

ConcatDoc is a Doc node that concatenates two child documents, preserving output order by printing the left child before the right. section 9.3.1

ConcatDoc participates in document construction and iterative pretty printing:

  • Create it with Concat(left, right), or use the overloaded + operator as a synonym for document concatenation. section 9.3.1
  • During Fits, test the left child first, then test the right child in the width remaining after the left child. section 9.3.3
  • During Pretty, push or print the left child before the right child while carrying group-fit and indentation state. section 9.3.4
  • Each processed ConcatDoc can increase the explicit work stack by one, so stack space is bounded by the number of ConcatDocs. section 9.3.3

Building a formatted expression

Combining foo, bar, parentheses, operators, and optional breaks produces Foo.Bar(xx + yy * zz) at width 30, Foo.Bar(\n xx + yy * zz) at width 20, and a more deeply broken layout at width 15.

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Explains construction, width checking, iterative printing, and work-stack growth without detailing ConcatDoc internals beyond child traversal.
Examples
Demonstrates expression formatting with Foo.Bar(xx + yy * zz) across widths 30, 20, and 15.
What it assumes
Assumes familiarity with document trees and optional breaks while defining concatenation through small compositional examples.
What you can do after
Build it from scratch as a C# document node supporting ordered composition, width testing, and iterative pretty printing.
How it connects
Connects ConcatDoc to Doc, Fits, Pretty, GroupDoc, IndentDoc, and OptBreakDoc.

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.