liveBook · Manning

Hierarchy

As explained in Clojure: The Essential Reference

A nested data structure is a data structure containing other data structures as elements or values at multiple levels.

Nested data structures contain other collections or values at multiple levels. Modeling them as trees makes parent-child relationships visible and gives a practical way to reason about traversing and transforming complex data. section 8.4 section 8.4.2

A tree interpretation depends on the conventions chosen for the data. One example treats a vector under `:n` as child nodes:

  • A vector marks a branching node; its items are children. section 8.4
  • A non-vector value under `:n` marks a terminal, or leaf, node; other map values are data belonging to that node. section 8.4
Figure 8.10. A possible tree rendition of a nested data structure.
39 nested data tree

See one possible tree rendition of the nested data structure. section 8.4

Traversal visits each node once. Depth-first traversal visits a node’s children before other nodes at the same level; breadth-first traversal visits nodes at the same level before moving deeper. Pre-order applies a function before descending, while post-order applies it after reaching the innermost items. section 8.4

Transforming nested collections

`clojure.walk/prewalk` and `postwalk` apply a one-argument function to nested items. For example, prewalk can inspect a pipeline node before descending, allowing processing of a branch to be skipped. The result generally retains the input collection type, depending on the transformation. section 8.4.2

How Clojure: The Essential Reference covers it

How deep it goes
Defines tree conventions and traversal orders, then explains prewalk and postwalk behavior, outputs, and a possible unsupported collection case.
Examples
Uses a map with vector-marked branches, a nested vector for visit order, and a workflow pipeline for branch handling.
What you can do after
Apply `clojure.walk/prewalk` or `postwalk` to inspect and transform items in nested collections.
How it connects
Connects nested structures to trees, depth-first and breadth-first traversal, and pre-order and post-order processing.

Also explained in

Compare how 7 books explain hierarchy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.