class Reaction {
constructor(left, right) {
const parse = f =>
f instanceof Formula
? [f]
: typeof f === 'string'
? f.split(/\s*,\s*/).map(Formula.parse)
: f.flatmap
? f.flatmap(parse)
: f instanceof Array
? f
: [f];
this.left = parse(left);
this.right = parse(right);
}
asTex() {
const l = this.left.map(s => s.asTex()).join(', ');
const r = this.right.map(s => s.asTex()).join(', ');
return `${l} \\rightarrow ${r}`;
}
balanceCheck() {
return balanceCheck(this.left)(this.right);
}
asHtml(block) {
const view = display => value => ((display.value = value), display);
return view((block ? tex.block : tex)(templateCallSite(this.asTex())))(
this
);
}
}