curry

说明

函数柯里化

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/function/curry

用法

curry.ts
curry.test.ts
import { curry } from "./ddzy/utility/function/curry";
//
const s1 = function (a: number, b: number, c: number, d: number) {
return a + b + c + d;
}
const p1 = curry(s1);
console.log(p1(1)(2, 3)(4));
console.log(p1(1, 2, 3, 4));
console.log(p1(1)(2, 3, 4));
import { curry } from "../../utility/function/curry";
describe('curry() tests...', () => {
test('method curry should works normally', () => {
const received = function (a: number, b: number, c: number, d: number) {
return a + b + c + d;
}
const curriedFunc = curry(received);
expect(curriedFunc(1, 2, 3)(4)).toBe(10);
expect(curriedFunc(100)(200)(300)(400)).toBe(1000);
expect(curriedFunc(23)(34, 45)(56)).toBe(158);
});
});