@esfx/async-iter-hierarchy Package
A Symbol-based API for defining an ECMAScript AsyncIterable with an inherent hierarchy.
Installation
npm i @esfx/async-iter-hierarchy
Usage
import { AsyncHierarchyIterable, Hierarchical, HierarchyProvider } from "@esfx/async-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 MyAsyncHierarchyIterable implements AsyncHierarchyIterable<Node> {
#nodes: AsyncIterable<Node>;
constructor(nodes: AsyncIterable<Node>) {
this.#nodes = nodes;
}
[Symbol.asyncIterator]() {
return this.#nodes[Symbol.asyncIterator]();
}
[Hierarchical.hierarchy]() {
return hierarchyProvider;
}
}
Interfaces
AsyncHierarchyIterable<TNode, T>
Represents an Iterable
with a navigable hierarchy.
AsyncOrderedHierarchyIterable<TNode, T>
Represents an AsyncIterable
with a navigable hierarchy that is inherently ordered.