import { Seq } from '../Utils/IterableUtils'; export declare type Node = T & { children: Array>; }; export interface ChildrenGetter { (t: T): T[]; } /** top-down tree node iterator */ export declare function preorder(root: T, getChildren: ChildrenGetter): Iterable; /** bottom-up tree node iterator */ export declare function postorder(root: T, getChildren: ChildrenGetter): Iterable; /** * Create a Seq of tree nodes in preorder sequence. * * 1 * / \ * / \ * / \ * 2 3 * / \ / * 4 5 6 * / / \ * 7 8 9 * * preorder: 1 2 4 7 5 3 6 8 9 * * @param {Object} root * @return {Seq} */ export declare function preorderSeq(root: Node): Seq>; /** * Create a Seq of tree nodes in postorder sequence. * * 1 * / \ * / \ * / \ * 2 3 * / \ / * 4 5 6 * / / \ * 7 8 9 * * postorder: 7 4 5 2 8 9 6 3 1 * * @param {Object} root * @return {Seq} */ export declare function postorderSeq(root: Node): Seq>; /** * Convert a tree into a new tree-like structure. The tree is traversed bottom- * up, and for each node, its mapped children are passed to the mapping * function. This allows the mapping function to integrate the mapped children * however it needs to. * * @param {mapFn} mapFn Mapping function to apply to each node. * @param {Function} getChildren A function that returns an iterable object over a node's children. * @param {any} root The root node of the tree whose structure is being mapped. */ export declare function mapStructure(mapFn: (node: T, mappedChildren: U[]) => U, getChildren: ChildrenGetter, root: T): U; /** * Convert a tree into a new structure, much like array.reduce. The tree is * traversed bottom-up. */ export declare const foldStructure: (reducer: (value: U, node: Node) => U, seed: U, root: Node) => U; /** * For any node in a tree that does not pass `nodePredicate`, replace it with * its children. A new tree will be returned. * * @param {Function} fn Predicate function to determine if a node * will be kept. * @param {Object} root Root node of a tree. * @return {Object} */ export declare function pruneDescendantNodes(fn: (node: Node) => boolean, root: Node): Node; /** * Recursively replace any node that does not pass `nodePredicate` with its * children. A new array of nodes will be returned. * * @param {Function} fn Predicate function to determine if a node * will be kept. * @param {Array} nodes An array of nodes. This will typically be the children * of a node in a tree. * @return {Array} */ export declare function pruneNodes(fn: (node: Node) => boolean, nodes: Node[]): Node[]; /** * If the root node has only one child, replace the root node with it's child. * * @param {Object} root Root node of a tree * @return {Object} Tree */ export declare function compactRootNodes(root: Node): Node; export declare function mapNodes(nodeTransform: (root: Node) => Node, root: Node): Node; /** * Get an array of nodes that satisfy nodePredicate */ export declare function filterNodes(nodePredicate: (node: Node) => boolean, node: Node): Node[]; /** * Simple convenience method to identify nodes that are leaves * @param {Object} node representing root of subtree (possibly a leaf) * @return {Boolean} indicates true if the node is a leaf and false otherwise */ export declare function isLeaf(node: T, getNodeChildren: ChildrenGetter): boolean; /** * Determine if a node is a branch * @param node * @param getNodeChildren */ export declare function isBranch(node: T, getNodeChildren: ChildrenGetter): boolean; /** * Using recursion to return all the leaf nodes for the given node. * @param {Object} node representing root of subtree * @param {Array} initial list of leaf nodes (optional) * @return {Array} updated list of leaf nodes */ export declare function getLeaves(node: T, getNodeChildren: ChildrenGetter): T[]; /** * Using recursion to return all the branch nodes for a given node * @param {Object} node representing root of subtree * @param {Array} initial list of branch nodes (optional) * @return {Array} updated list of branch nodes */ export declare function getBranches(node: T, getNodeChildren: ChildrenGetter, branches?: T[]): T[]; //# sourceMappingURL=TreeUtils.d.ts.map