pretty print enhancements + comparison of generic functions
This commit is contained in:
parent
bbac7858ae
commit
9e1f679dba
15 changed files with 93 additions and 45 deletions
|
|
@ -1,6 +1,5 @@
|
|||
import { inspect } from 'node:util';
|
||||
import { symbolDict, symbolFunction, symbolList, symbolProduct, symbolSum } from '../structures/type_constructors.js';
|
||||
import { symbolSet } from "../structures/type_constructors.js";
|
||||
import { symbolDict, symbolFunction, symbolList, symbolProduct, symbolSum, symbolSet } from '../structures/type_constructors.js';
|
||||
import { getHumanReadableName } from '../primitives/symbol.js';
|
||||
import { getSymbol } from '../primitives/type.js';
|
||||
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@
|
|||
import createRBTree from "functional-red-black-tree";
|
||||
import { inspect } from "util";
|
||||
|
||||
function defaultPrintf(depth, options, inspect) {
|
||||
const entries = [];
|
||||
this.tree.forEach((key, val) => { entries.push(`${inspect(key)} => ${inspect(val)}`); });
|
||||
return `RBTree(${this.tree.length}) {${entries.join(', ')}}`;
|
||||
}
|
||||
|
||||
export class RBTreeWrapper {
|
||||
constructor(tree) {
|
||||
constructor(tree, printf = defaultPrintf) {
|
||||
this.tree = tree;
|
||||
this[inspect.custom] = printf;
|
||||
}
|
||||
|
||||
static new(compareFn) {
|
||||
return new RBTreeWrapper(createRBTree(compareFn))
|
||||
}
|
||||
|
||||
// pretty print to console
|
||||
[inspect.custom](depth, options, inspect) {
|
||||
const entries = [];
|
||||
this.tree.forEach((key, val) => { entries.push(`${inspect(key)} => ${inspect(val)}`); });
|
||||
return `RBTree(${this.tree.length}) {${entries.join(', ')}}`;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,3 +18,7 @@ export const memoize = callback => {
|
|||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
export const indent = (multiline, n) => {
|
||||
return multiline.split('\n').map(line => ' '.repeat(n)+line).join('\n');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue