diff --git a/h24s_25/src/ts/higherorderfunctionball.ts b/h24s_25/src/ts/higherorderfunctionball.ts new file mode 100644 index 0000000..fb44096 --- /dev/null +++ b/h24s_25/src/ts/higherorderfunctionball.ts @@ -0,0 +1,36 @@ +import{BallTypeEnum} from './balltypes'; +import {BallInterface, HigherOrderFunctionBallInterface, NumberBallInterface, FunctionBallInterface} from './ballInterface'; + +export class HigherOrderFunctionBall< + S1 extends BallInterface|null, + O1 extends BallInterface|null, + S2 extends BallInterface|null, + O2 extends BallInterface|null, +> extends HigherOrderFunctionBallInterface{ + symbol: string; + applied: number[]; + private readonly funcVal: (f: FunctionBallInterface) => {self: S2, other: O2}; + + constructor(func: (f: FunctionBallInterface) => {self: S2, other: O2}, symbol: string, applied: number[]) { + super(); + this.funcVal = func; + this.symbol = symbol; + this.applied = applied; + } + override func(f: FunctionBallInterface): { self: S2, other: O2 } { + return this.funcVal(f); + } + ballType(): BallTypeEnum { + return BallTypeEnum.HIGHER_ORDER_FUNCTION; + } + + label(): string{ + let label: string = this.symbol; + this.applied.forEach( + function (value) { + label += ` ${value.toString}` + } + ) + return label; + } +} \ No newline at end of file