import type { Show } from "@principia/prelude"; import type { Forest, Tree } from "./model"; const draw = (S: Show) => (indentation: string, forest: Forest): string => { let r = ""; const len = forest.length; let tree: Tree; for (let i = 0; i < len; i++) { tree = forest[i]; const isLast = i === len - 1; r += indentation + (isLast ? "└" : "├") + "─ " + S.show(tree.value); r += draw(S)(indentation + (len > 1 && !isLast ? "│ " : " "), tree.forest); } return r; }; export const drawForest = (S: Show) => (forest: Forest): string => draw(S)("\n", forest); export const drawTree = (S: Show) => (tree: Tree): string => S.show(tree.value) + drawForest(S)(tree.forest); export const getShow = (S: Show): Show> => ({ show: drawTree(S) });