From ff2c4aa1d7166fb486f2feaddde4bb5c5ca5359f Mon Sep 17 00:00:00 2001 From: Mozuya Date: Sun, 16 Jun 2024 12:10:02 +0900 Subject: [PATCH] =?UTF-8?q?HIgherOrderFunctionBall=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- h24s_25/src/ts/higherorderfunctionball.ts | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 h24s_25/src/ts/higherorderfunctionball.ts 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