@esfx/iter-hierarchy Package
A Symbol-based API for defining an Iterable with an inherent hierarchy.
Installation
npm i @esfx/iter-hierarchy
Usage
import { HierarchyIterable, Hierarchical, HierarchyProvider } from "@esfx/iter-hierarchy";
interface Node {
parent?: Node;
children?: Node[];
// ...
}
const hierarchyProvider: HierarchyProvider<Node> = {
parent(node: Node) { return node.parent; },
children(node: Node) { return node.children; },
};
class MyHierarchyIterable implements HierarchyIterable<Node> {
#nodes: Iterable<Node>;
constructor(nodes: Iterable<Node>) {
this.#nodes = nodes;
}
[Symbol.iterator]() {
return this.#nodes[Symbol.iterator]();
}
[Hierarchical.hierarchy]() {
return hierarchyProvider;
}
}
Interfaces
Hierarchical<TNode>
Describes an object that has a navigable hierarchy.
HierarchyIterable<TNode, T>
Represents an Iterable
with a navigable hierarchy.
HierarchyProvider<TNode>
Describes an object that defines the relationships between parents and children of an element.
OrderedHierarchyIterable<TNode, T>
Represents an Iterable
with a navigable hierarchy that is inherently ordered.
Namespaces
Axis
Axis traversal helpers.