import {Objects} from "../type/Objects"; import {BiFunctionImpl} from "./BiFunctionImpl"; import {comparator} from "../Interface"; export abstract class BinaryOperator extends BiFunctionImpl{ private constructor() {super();} public static minBy?(comparator:comparator):BinaryOperator{ Objects.requireNotNull(comparator); return new class extends BinaryOperator{ apply = (a: T, b: T): T => comparator.compare(a,b) <= 0 ? a : b; }; } public static maxBy?(comparator:comparator):BinaryOperator{ Objects.requireNotNull(comparator); return new class extends BinaryOperator{ apply = (a: T, b: T): T => comparator.compare(a,b) >= 0 ? a : b; }; } public static from(other:Function):BinaryOperator{ if(other instanceof BinaryOperator) return other; return new class extends BinaryOperator{ apply = (a: T, b: T): T => other(a, b); }; } public call(thisArg: any, ...argArray:any[]): any {return this.apply((argArray)[0],(argArray)[1]);} } Object.package(this);