_ = {
const {Tree, Node, Empty} = newType('Tree', {
Node: (key, left, right) => ({key, left, right}),
Empty: () => {}
});
const getEdgeString = (key, child) => match({
[Node]: ({key: childKey}) => `${key.show()} -> ${childKey.show()}`,
[Empty]: () => {}
})(child);
const getEdges = match({
[Node]: ({key, left, right}) => {
const leftEdge = getEdgeString(key, left);
const rightEdge = getEdgeString(key, right);
const edges = [];
if (leftEdge) { edges.push(leftEdge); }
if (rightEdge) { edges.push(rightEdge); }
return edges.concat(getEdges(left), getEdges(right));
},
[Empty]: () => []
});
const toDot = tree => `digraph { ${getEdges(tree).join('; ')} }`;
instance(Tree, Dot, {toDot});
return {Tree, Node, Empty};
}