Skip to content

clojure.core/tree-seq

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 10 Runnable: 6
([branch? children root])

Returns a lazy sequence of the nodes in a tree, via a depth-first walk. branch? must be a fn of one arg that returns true if passed a node that can have children (but may not). children must be a fn of one arg that returns a sequence of the children. Will only be called on nodes for which branch? returns true. Root is the root node of the tree.

Examples

by devn on
by patazj on
by algal on
by gregginca on
by devn on . May have evaluation errors.
by shark8me on . May have evaluation errors.
by phreed on
by MokkeMeguru on . May have evaluation errors.
by kovasap on
by jacobmendoza on . May have evaluation errors.

Note by phreed

The 'branch?' and 'children' functions perform different types of filtering. The 'branch?' function examines a node and determines whether there are children that need to be included in the processing. The 'children' function selects (or generates) the children to be included in the returned sequence.

Note by lostdiaspora

Example 5 has for the second example (tree-seq seq? seq [[1 2 [3]] [4]]) when it should be (tree-seq sequential? seq [[1 2 [3]] [4]])

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.