Function partial

  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1) => R)

      The function to partially apply.

        • (arg1): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    Returns (() => R)

    A new function that takes no arguments and returns the result of the original function.

      • (): R
      • Returns R

    const addOne = (x: number) => x + 1;
    const addOneToFive = partial(addOne, 5);
    console.log(addOneToFive()); // => 6
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2) => R)

      The function to partially apply.

        • (arg1, arg2): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    Returns ((arg2: T2) => R)

    A new function that takes the second argument and returns the result of the original function.

      • (arg2): R
      • Parameters

        Returns R

    const multiply = (x: number, y: number) => x * y;
    const double = partial(multiply, 2);
    console.log(double(5)); // => 10
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2) => R)

      The function to partially apply.

        • (arg1, arg2): R
        • Parameters

          Returns R

    • placeholder: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: T2

      The second argument to apply.

    Returns ((arg1: T1) => R)

    A new function that takes the first argument and returns the result of the original function.

      • (arg1): R
      • Parameters

        Returns R

    const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
    const greetWithHello = partial(greet, partial.placeholder, 'John');
    console.log(greetWithHello('Hello')); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3) => R)

      The function to partially apply.

        • (arg1, arg2, arg3): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    Returns ((arg2: T2, arg3: T3) => R)

    A new function that takes the second and third arguments and returns the result of the original function.

      • (arg2, arg3): R
      • Parameters

        Returns R

    const sumThree = (a: number, b: number, c: number) => a + b + c;
    const addFive = partial(sumThree, 5);
    console.log(addFive(3, 2)); // => 10
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3) => R)

      The function to partially apply.

        • (arg1, arg2, arg3): R
        • Parameters

          Returns R

    • arg1: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: T2

      The second argument to apply.

    Returns ((arg1: T1, arg3: T3) => R)

    A new function that takes the first and third arguments and returns the result of the original function.

      • (arg1, arg3): R
      • Parameters

        Returns R

    const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
    const greetWithPlaceholder = partial(greet, partial.placeholder, 'John');
    console.log(greetWithPlaceholder('Hello')); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3) => R)

      The function to partially apply.

        • (arg1, arg2, arg3): R
        • Parameters

          Returns R

    • arg1: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: typeof partialPlaceholder

      The placeholder for the second argument.

    • arg3: T3

      The third argument to apply.

    Returns ((arg1: T1, arg2: T2) => R)

    A new function that takes the first and second arguments and returns the result of the original function.

      • (arg1, arg2): R
      • Parameters

        Returns R

    const multiply = (x: number, y: number, z: number) => x * y * z;
    const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2);
    console.log(multiplyWithPlaceholders(3, 4)); // => 24
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3) => R)

      The function to partially apply.

        • (arg1, arg2, arg3): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    • arg2: typeof partialPlaceholder

      The placeholder for the second argument.

    • arg3: T3

      The third argument to apply.

    Returns ((arg2: T2) => R)

    A new function that takes the second argument and returns the result of the original function.

      • (arg2): R
      • Parameters

        Returns R

    const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
    const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder);
    console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3) => R)

      The function to partially apply.

        • (arg1, arg2, arg3): R
        • Parameters

          Returns R

    • plc1: typeof partialPlaceholder
    • arg2: T2

      The placeholder for the second argument.

    • arg3: T3

      The third argument to apply.

    Returns ((arg1: T1) => R)

    A new function that takes the second argument and returns the result of the original function.

      • (arg1): R
      • Parameters

        Returns R

    const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
    const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder);
    console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    Returns ((arg2: T2, arg3: T3, arg4: T4) => R)

    A new function that takes the second argument and returns the result of the original function.

      • (arg2, arg3, arg4): R
      • Parameters

        Returns R

    const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
    const double = partial(multiply, 2);
    console.log(double(5, 4, 3)); // => 120
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: typeof partialPlaceholder

      The placeholder for the second argument.

    • arg3: T3

      The third argument to apply.

    • arg4: T4

      The fourth argument to apply.

    Returns ((arg1: T1, arg2: T2) => R)

    A new function that takes the first and second arguments and returns the result of the original function.

      • (arg1, arg2): R
      • Parameters

        Returns R

    const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
    const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3);
    console.log(multiplyWithPlaceholders(4, 5)); // => 120
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    • arg2: T2

      The second argument to apply.

    Returns ((arg3: T3, arg4: T4) => R)

    A new function that takes the third and fourth arguments and returns the result of the original function.

      • (arg3, arg4): R
      • Parameters

        Returns R

    const sumFour = (a: number, b: number, c: number, d: number) => a + b + c + d;
    const addOneAndTwo = partial(sumFour, 1, 2);
    console.log(addOneAndTwo(3, 4)); // => 10
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    • arg2: typeof partialPlaceholder

      The placeholder for the second argument.

    • arg3: T3

      The third argument to apply.

    Returns ((arg2: T2, arg4: T4) => R)

    A new function that takes the second and fourth arguments and returns the result of the original function.

      • (arg2, arg4): R
      • Parameters

        Returns R

    const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
    const greetWithPlaceholder = partial(greet, 'Hello', partial.placeholder, '!');
    console.log(greetWithPlaceholder('John')); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: T2

      The second argument to apply.

    • arg3: T3

      The third argument to apply.

    Returns ((arg1: T1, arg4: T4) => R)

    A new function that takes the first and third arguments and returns the result of the original function.

      • (arg1, arg4): R
      • Parameters

        Returns R

    const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
    const multiplyWithPlaceholder = partial(multiply, partial.placeholder, 2, 3);
    console.log(multiplyWithPlaceholder(4)); // => 24
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: T2

      The second argument to apply.

    • arg3: typeof partialPlaceholder

      The placeholder for the third argument.

    • arg4: T4

      The fourth argument to apply.

    Returns ((arg1: T1, arg3: T3) => R)

    A new function that takes the first and third arguments and returns the result of the original function.

      • (arg1, arg3): R
      • Parameters

        Returns R

  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: typeof partialPlaceholder

      The placeholder for the second argument.

    • arg3: T3

      The third argument to apply.

    • arg4: T4

      The fourth argument to apply.

    Returns ((arg1: T1, arg2: T2) => R)

    A new function that takes the first and second arguments and returns the result of the original function.

      • (arg1, arg2): R
      • Parameters

        Returns R

    const multiply = (x: number, y: number, z: number, w: number) => x * y * z * w;
    const multiplyWithPlaceholders = partial(multiply, partial.placeholder, partial.placeholder, 2, 3);
    console.log(multiplyWithPlaceholders(4, 5)); // => 120
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    • arg2: T2

      The second argument to apply.

    • arg3: T3

      The third argument to apply.

    Returns ((arg4: T4) => R)

    A new function that takes the fourth argument and returns the result of the original function.

      • (arg4): R
      • Parameters

        Returns R

  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    • arg2: T2

      The second argument to apply.

    • arg3: typeof partialPlaceholder

      The placeholder for the third argument.

    • arg4: T4

      The fourth argument to apply.

    Returns ((arg3: T3) => R)

    A new function that takes the third argument and returns the result of the original function.

      • (arg3): R
      • Parameters

        Returns R

  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: T1

      The first argument to apply.

    • arg2: typeof partialPlaceholder

      The placeholder for the second argument.

    • arg3: T3

      The third argument to apply.

    • arg4: T4

      The fourth argument to apply.

    Returns ((arg2: T2) => R)

    A new function that takes the second argument and returns the result of the original function.

      • (arg2): R
      • Parameters

        Returns R

  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => R)

      The function to partially apply.

        • (arg1, arg2, arg3, arg4): R
        • Parameters

          Returns R

    • arg1: typeof partialPlaceholder

      The placeholder for the first argument.

    • arg2: T2

      The second argument to apply.

    • arg3: T3

      The third argument to apply.

    • arg4: T4

      The fourth argument to apply.

    Returns ((arg1: T1) => R)

    A new function that takes the first argument and returns the result of the original function.

      • (arg1): R
      • Parameters

        Returns R

  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • TS extends any[]

      The types of the arguments.

    • R

      The return type of the function.

    Parameters

    • func: ((...args: TS) => R)

      The function to partially apply.

        • (...args): R
        • Parameters

          • Rest...args: TS

          Returns R

    Returns ((...args: TS) => R)

    A new function that takes the same arguments as the original function.

      • (...args): R
      • Parameters

        • Rest...args: TS

        Returns R

    const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0);
    const addFive = partial(add, 5);
    console.log(addFive(1, 2, 3)); // => 11
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • TS extends any[]

      The types of the arguments.

    • T1

      The type of the first argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, ...args: TS) => R)

      The function to partially apply.

        • (arg1, ...args): R
        • Parameters

          • arg1: T1
          • Rest...args: TS

          Returns R

    • arg1: T1

      The first argument to apply.

    Returns ((...args: TS) => R)

    A new function that takes the remaining arguments and returns the result of the original function.

      • (...args): R
      • Parameters

        • Rest...args: TS

        Returns R

    const greet = (greeting: string, ...names: string[]) => `${greeting}, ${names.join(', ')}!`;
    const greetHello = partial(greet, 'Hello');
    console.log(greetHello('Alice', 'Bob')); // => 'Hello, Alice, Bob!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • TS extends any[]

      The types of the arguments.

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • R

      The return type of the function.

    Parameters

    • func: ((arg1: T1, arg2: T2, ...args: TS) => R)

      The function to partially apply.

        • (arg1, arg2, ...args): R
        • Parameters

          • arg1: T1
          • arg2: T2
          • Rest...args: TS

          Returns R

    • t1: T1
    • arg2: T2

      The second argument to apply.

    Returns ((...args: TS) => R)

    A new function that takes the remaining arguments and returns the result of the original function.

      • (...args): R
      • Parameters

        • Rest...args: TS

        Returns R

    const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
    const greetWithHello = partial(greet, 'Hello', '!');
    console.log(greetWithHello('John')); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • TS extends any[]

      The types of the arguments.

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • R

      The return type of the function.

    Parameters

    • func: ((t1: T1, arg2: T2, arg3: T3, ...args: TS) => R)

      The function to partially apply.

        • (t1, arg2, arg3, ...args): R
        • Parameters

          Returns R

    • t1: T1

      The first argument to apply.

    • arg2: T2

      The second argument to apply.

    • arg3: T3

      The third argument to apply.

    Returns ((...args: TS) => R)

    A new function that takes the remaining arguments and returns the result of the original function.

      • (...args): R
      • Parameters

        • Rest...args: TS

        Returns R

    const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
    const greetWithHello = partial(greet, 'Hello', 'John', '!');
    console.log(greetWithHello()); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • TS extends any[]

      The types of the arguments.

    • T1

      The type of the first argument.

    • T2

      The type of the second argument.

    • T3

      The type of the third argument.

    • T4

      The type of the fourth argument.

    • R

      The return type of the function.

    Parameters

    • func: ((t1: T1, arg2: T2, arg3: T3, arg4: T4, ...args: TS) => R)

      The function to partially apply.

        • (t1, arg2, arg3, arg4, ...args): R
        • Parameters

          Returns R

    • t1: T1

      The first argument to apply.

    • arg2: T2

      The second argument to apply.

    • arg3: T3

      The third argument to apply.

    • arg4: T4

      The fourth argument to apply.

    Returns ((...args: TS) => R)

    A new function that takes the remaining arguments and returns the result of the original function.

      • (...args): R
      • Parameters

        • Rest...args: TS

        Returns R

    const greet = (greeting: string, name: string, punctuation: string) => `${greeting}, ${name}${punctuation}`;
    const greetWithHello = partial(greet, 'Hello', 'John', '!');
    console.log(greetWithHello()); // => 'Hello, John!'
  • Creates a function that invokes func with partialArgs prepended to the arguments it receives. This method is like bind except it does not alter the this binding.

    The partial.placeholder value, which defaults to a symbol, may be used as a placeholder for partially applied arguments.

    Note: This method doesn't set the length property of partially applied functions.

    Type Parameters

    • F extends ((...args: any[]) => any)

      The type of the function to partially apply.

    Parameters

    • func: F

      The function to partially apply.

    • Rest...partialArgs: any[]

      The arguments to be partially applied.

    Returns ((...args: any[]) => ReturnType<F>)

    A new function that takes the remaining arguments and returns the result of the original function.

      • (...args): ReturnType<F>
      • Parameters

        • Rest...args: any[]

        Returns ReturnType<F>

    const add = (...numbers: number[]) => numbers.reduce((sum, n) => sum + n, 0);
    const addFive = partial(add, 5);
    console.log(addFive(1, 2, 3)); // => 11

Properties

Properties

placeholder: typeof partialPlaceholder