Function partialRight

  • Partially applies arguments to a function, fixing some parameters from the right.

    Type Parameters

    • T extends unknown[]

      The tuple type of the remaining arguments.

    • U extends unknown[]

      The tuple type of the fixed arguments.

    • R

      The return type of the function.

    Parameters

    • fn: ((...args: [...T[], ...U[]]) => R)

      The function to partially apply.

        • (...args): R
        • Parameters

          • Rest...args: [...T[], ...U[]]

          Returns R

    • Rest...presetArgs: U

      The arguments to fix from the right.

    Returns ((...remainingArgs: T) => R)

    • A new function that takes only the remaining arguments.
      • (...remainingArgs): R
      • Parameters

        • Rest...remainingArgs: T

        Returns R

    const formatDate = (year: number, month: number, day: number) => `${year}-${month}-${day}`;
    const formatThisYear = partialRight(formatDate, 2024);
    console.log(formatThisYear(5, 12)); // Output: "5-12-2024"