1.1.0 • Published 4 years ago
js-rosetree v1.1.0
js-rosetree
Set of utilities for creating and manipulating Rosetrees.
What are Rosetrees?
Rosetrees, also known as Multi-way trees, are tree data structures that allows nodes to have any number of children, and then number of children can be different for each node. They are useful for representing a wide variety of data that can not be represented cleanly in other tree data structures.
Install
npm i js-rosetree
Usage
import { tree as Tree, zipper as Zipper } from "js-rosetree";
const { tree, singleton } = Tree;
const myTree = tree("a", [
singleton("b"),
tree("c", [singleton("d"), singleton("e")]),
]);
const myZipper = Zipper.fromTree(myTree);
console.dir(Zipper.label(Zipper.forward(myZipper))); // "b"
console.dir(Zipper.label(Zipper.findNext(myZipper, (l) => l === "e"))); // "e"
console.dir(
Zipper.label(Zipper.root(Zipper.findNext(myZipper, (l) => l === "e")))
); // "a"