f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/main/js/formulas/logic/XOR.ts
-rw-r--r--
1073
 1import { isNotNull } from "../../utils/Other";
 2import { ValueException } from "../../errors/ValueException";
 3import { SheetColumnRowKey } from "../../models/common/SheetColumnRowKey";
 4import { Complex } from "../../models/common/Types";
 5import { Converters } from "../../utils/Converters";
 6import { Mappers } from "../../utils/Mappers";
 7import { Reducers } from "../../utils/Reducers";
 8import { AbstractFormula } from "../AbstractFormula";
 9import { FormulaName } from "../FormulaName";
10
11export class XOR extends AbstractFormula {
12  static SELF: XOR = new XOR();
13  NAME = FormulaName.OR;
14
15  internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
16    AbstractFormula.checkAtLeastLength(values.length, 1, this.NAME);
17    const filteredValues = values
18      .map(this.lookup)
19      .map(Mappers.toFlatStream)
20      .reduce(Reducers.join)
21      .filter(isNotNull);
22    if (filteredValues.length === 0) {
23      return new ValueException("OR has no valid input data.");
24    }
25    return filteredValues.map(Converters.toBoolean).reduce(Reducers.logicalXOr, false);
26  }
27}