Function curryRight

  • Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

    Unlike curry, this function curries the function from right to left.

    Type Parameters

    • R

    Parameters

    • func: (() => R)

      The function to curry.

        • (): R
        • Returns R

    Returns (() => R)

    A curried function.

      • (): R
      • Returns R

    function noArgFunc() {
    return 42;
    }
    const curriedNoArgFunc = curryRight(noArgFunc);
    console.log(curriedNoArgFunc()); // 42
  • Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

    Unlike curry, this function curries the function from right to left.

    Type Parameters

    • P
    • R

    Parameters

    • func: ((p: P) => R)

      The function to curry.

        • (p): R
        • Parameters

          Returns R

    Returns ((p: P) => R)

    A curried function.

      • (p): R
      • Parameters

        Returns R

    function oneArgFunc(a: number) {
    return a * 2;
    }
    const curriedOneArgFunc = curryRight(oneArgFunc);
    console.log(curriedOneArgFunc(5)); // 10
  • Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

    Unlike curry, this function curries the function from right to left.

    Type Parameters

    • P1
    • P2
    • R

    Parameters

    • func: ((p1: P1, p2: P2) => R)

      The function to curry.

        • (p1, p2): R
        • Parameters

          Returns R

    Returns ((p2: P2) => ((p1: P1) => R))

    A curried function.

      • (p2): ((p1: P1) => R)
      • Parameters

        Returns ((p1: P1) => R)

          • (p1): R
          • Parameters

            Returns R

    function twoArgFunc(a: number, b: number) {
    return [a, b];
    }
    const curriedTwoArgFunc = curryRight(twoArgFunc);
    const func = curriedTwoArgFunc(1);
    console.log(func(2)); // [2, 1]
  • Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

    Unlike curry, this function curries the function from right to left.

    Type Parameters

    • P1
    • P2
    • P3
    • R

    Parameters

    • func: ((p1: P1, p2: P2, p3: P3) => R)

      The function to curry.

        • (p1, p2, p3): R
        • Parameters

          Returns R

    Returns ((p3: P3) => ((p2: P2) => ((p1: P1) => R)))

    A curried function.

      • (p3): ((p2: P2) => ((p1: P1) => R))
      • Parameters

        Returns ((p2: P2) => ((p1: P1) => R))

          • (p2): ((p1: P1) => R)
          • Parameters

            Returns ((p1: P1) => R)

              • (p1): R
              • Parameters

                Returns R

    function threeArgFunc(a: number, b: number, c: number) {
    return [a, b, c];
    }
    const curriedThreeArgFunc = curryRight(threeArgFunc);
    const func = curriedThreeArgFunc(1);
    const func2 = func(2);
    console.log(func2(3)); // [3, 2, 1]
  • Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

    Unlike curry, this function curries the function from right to left.

    Type Parameters

    • P1
    • P2
    • P3
    • P4
    • R

    Parameters

    • func: ((p1: P1, p2: P2, p3: P3, p4: P4) => R)

      The function to curry.

        • (p1, p2, p3, p4): R
        • Parameters

          Returns R

    Returns ((p4: P4) => ((p3: P3) => ((p2: P2) => ((p1: P1) => R))))

    A curried function.

      • (p4): ((p3: P3) => ((p2: P2) => ((p1: P1) => R)))
      • Parameters

        Returns ((p3: P3) => ((p2: P2) => ((p1: P1) => R)))

          • (p3): ((p2: P2) => ((p1: P1) => R))
          • Parameters

            Returns ((p2: P2) => ((p1: P1) => R))

              • (p2): ((p1: P1) => R)
              • Parameters

                Returns ((p1: P1) => R)

                  • (p1): R
                  • Parameters

                    Returns R

    function fourArgFunc(a: number, b: number, c: number, d: number) {
    return [a, b, c, d];
    }
    const curriedFourArgFunc = curryRight(fourArgFunc);
    const func = curriedFourArgFunc(1);
    const func2 = func(2);
    const func3 = func2(3);
    console.log(func3(4)); // [4, 3, 2, 1]
  • Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

    Unlike curry, this function curries the function from right to left.

    Type Parameters

    • P1
    • P2
    • P3
    • P4
    • P5
    • R

    Parameters

    • func: ((p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R)

      The function to curry.

        • (p1, p2, p3, p4, p5): R
        • Parameters

          Returns R

    Returns ((p5: P5) => ((p4: P4) => ((p3: P3) => ((p2: P2) => ((p1: P1) => R)))))

    A curried function.

      • (p5): ((p4: P4) => ((p3: P3) => ((p2: P2) => ((p1: P1) => R))))
      • Parameters

        Returns ((p4: P4) => ((p3: P3) => ((p2: P2) => ((p1: P1) => R))))

          • (p4): ((p3: P3) => ((p2: P2) => ((p1: P1) => R)))
          • Parameters

            Returns ((p3: P3) => ((p2: P2) => ((p1: P1) => R)))

              • (p3): ((p2: P2) => ((p1: P1) => R))
              • Parameters

                Returns ((p2: P2) => ((p1: P1) => R))

                  • (p2): ((p1: P1) => R)
                  • Parameters

                    Returns ((p1: P1) => R)

                      • (p1): R
                      • Parameters

                        Returns R

    function fiveArgFunc(a: number, b: number, c: number, d: number, e: number) {
    return [a, b, c, d, e];
    }
    const curriedFiveArgFunc = curryRight(fiveArgFunc);
    const func = curriedFiveArgFunc(1);
    const func2 = func(2);
    const func3 = func2(3);
    const func4 = func3(4);
    console.log(func4(5)); // [5, 4, 3, 2, 1]
  • Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument. This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.

    Unlike curry, this function curries the function from right to left.

    Parameters

    • func: ((...args: any[]) => any)

      The function to curry.

        • (...args): any
        • Parameters

          • Rest...args: any[]

          Returns any

    Returns ((...args: any[]) => any)

    A curried function.

      • (...args): any
      • Parameters

        • Rest...args: any[]

        Returns any

    function sum(a: number, b: number, c: number) {
    return a + b + c;
    }

    const curriedSum = curryRight(sum);

    // The parameter `c` should be given the value `10`.
    const add10 = curriedSum(10);

    // The parameter `b` should be given the value `15`.
    const add25 = add10(15);

    // The parameter `a` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
    const result = add25(5); // 30