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
|
|
@ -2,13 +2,21 @@ import { newRight } from "./sum.js";
|
|||
import { newProduct } from "./product.js";
|
||||
import { unit } from "../primitives/unit.js";
|
||||
import { RBTreeWrapper } from "../util/rbtree_wrapper.js";
|
||||
import { indent } from "../util/util.js";
|
||||
|
||||
// only for debugging
|
||||
function inspectSet(_depth, options, inspect) {
|
||||
const keys = [];
|
||||
this.tree.forEach((key) => { keys.push(inspect(key, options)); });
|
||||
return `{\n${indent(keys.join(',\n'), 2)}\n}`;
|
||||
}
|
||||
|
||||
// (a -> a -> Int) -> Set(a)
|
||||
export const emptySet = compareFn => RBTreeWrapper.new((x, y) => compareFn(x)(y));
|
||||
export const emptySet = compareFn => RBTreeWrapper.new((x, y) => compareFn(x)(y), inspectSet);
|
||||
|
||||
export const has = set => key => set.tree.get(key) === true;
|
||||
export const add = set => key => set.tree.get(key) === true ? set : new RBTreeWrapper(set.tree.insert(key, true));
|
||||
export const remove = set => key => new RBTreeWrapper(set.tree.remove(key));
|
||||
export const add = set => key => set.tree.get(key) === true ? set : new RBTreeWrapper(set.tree.insert(key, true), inspectSet);
|
||||
export const remove = set => key => new RBTreeWrapper(set.tree.remove(key), inspectSet);
|
||||
export const length = set => set.tree.length;
|
||||
|
||||
export const fold = set => callback => initial => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue