Skip to content

Commit

Permalink
fix(partial): rename return function name
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokiMiyauci committed Jun 5, 2023
1 parent 1d17b11 commit 2ab4f3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 5 additions & 9 deletions partial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export function partial<
fn: (...args: readonly [...T, ...U]) => R,
...args: T
): (...rest: U) => R {
function partial(...rest: U): R {
return function bound(...rest: U): R {
return fn(...args, ...rest);
}

return partial;
};
}

/** Create right partial applied function.
Expand Down Expand Up @@ -90,7 +88,7 @@ export function partialRight<AX, R>(
...args: AX[]
): (...args: readonly AX[]) => R {
args = args.reverse();
return function partial(...rest): R {
return function bound(...rest): R {
return fn.apply(null, rest.concat(args));
};
}
Expand Down Expand Up @@ -118,9 +116,7 @@ export function partialTail<
fn: (...args: readonly [H, ...T, ...U]) => R,
...tail: T
): (head: H, ...rest: U) => R {
function partial(head: H, ...rest: U): R {
return function bound(head: H, ...rest: U): R {
return fn(head, ...tail, ...rest);
}

return partial;
};
}
11 changes: 11 additions & 0 deletions partial_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type Fn2Spy<T> = T extends (this: infer T, ...args: infer Args) => infer R
: unknown;

describe("partial", () => {
it("should return function what name is bound", () => {
assertEquals(partial(() => "").name, "bound");
});
describe("arity 1", function () {
interface Context {
fn: Fn2Spy<Arity1>;
Expand Down Expand Up @@ -136,6 +139,10 @@ describe("partial", () => {
});

describe("partialRight", () => {
it("should return function what name is bound", () => {
assertEquals(partialRight(() => "").name, "bound");
});

describe("nullary", () => {
interface Context {
fn: Fn2Spy<Nullabry>;
Expand Down Expand Up @@ -240,6 +247,10 @@ describe("partialRight", () => {
});

describe("partialTail", () => {
it("should return function what name is bound", () => {
assertEquals(partialTail(() => "").name, "bound");
});

describe("unary", () => {
interface Context {
fn: Fn2Spy<Arity1>;
Expand Down

0 comments on commit 2ab4f3b

Please sign in to comment.