Function flowRight

  • Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

    The this context of the returned function is also passed to the functions provided as parameters.

    This method is like flow except that it creates a function that invokes the given functions from right to left.

    Type Parameters

    • R

    Parameters

    • f: (() => R)

      The function to invoke.

        • (): R
        • Returns R

    Returns (() => R)

    Returns the new composite function.

      • (): R
      • Returns R

    function noArgFunc() {
    return 42;
    }
    const combined = flowRight(noArgFunc);
    console.log(combined()); // 42
  • Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

    The this context of the returned function is also passed to the functions provided as parameters.

    This method is like flow except that it creates a function that invokes the given functions from right to left.

    Type Parameters

    • A extends any[]
    • R

    Parameters

    • f1: ((...args: A) => R)

      The function to invoke.

        • (...args): R
        • Parameters

          • Rest...args: A

          Returns R

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

    Returns the new composite function.

      • (...args): R
      • Parameters

        • Rest...args: A

        Returns R

    function oneArgFunc(a: number) {
    return a * 2;
    }
    const combined = flowRight(oneArgFunc);
    console.log(combined(5)); // 10
  • Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

    The this context of the returned function is also passed to the functions provided as parameters.

    This method is like flow except that it creates a function that invokes the given functions from right to left.

    Type Parameters

    • A extends any[]
    • R1
    • R2

    Parameters

    • f2: ((a: R1) => R2)

      The function to invoke.

        • (a): R2
        • Parameters

          Returns R2

    • f1: ((...args: A) => R1)

      The function to invoke.

        • (...args): R1
        • Parameters

          • Rest...args: A

          Returns R1

    Returns ((...args: A) => R2)

    Returns the new composite function.

      • (...args): R2
      • Parameters

        • Rest...args: A

        Returns R2

    const add = (x: number, y: number) => x + y;
    const square = (n: number) => n * n;

    const combined = flowRight(square, add);
    console.log(combined(1, 2)); // 9
  • Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

    The this context of the returned function is also passed to the functions provided as parameters.

    This method is like flow except that it creates a function that invokes the given functions from right to left.

    Type Parameters

    • A extends any[]
    • R1
    • R2
    • R3

    Parameters

    • f3: ((a: R2) => R3)

      The function to invoke.

        • (a): R3
        • Parameters

          Returns R3

    • f2: ((a: R1) => R2)

      The function to invoke.

        • (a): R2
        • Parameters

          Returns R2

    • f1: ((...args: A) => R1)

      The function to invoke.

        • (...args): R1
        • Parameters

          • Rest...args: A

          Returns R1

    Returns ((...args: A) => R3)

    Returns the new composite function.

      • (...args): R3
      • Parameters

        • Rest...args: A

        Returns R3

    const add = (x: number, y: number) => x + y;
    const square = (n: number) => n * n;
    const double = (n: number) => n * 2;

    const combined = flowRight(double, square, add);
    console.log(combined(1, 2)); // 18
  • Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

    The this context of the returned function is also passed to the functions provided as parameters.

    This method is like flow except that it creates a function that invokes the given functions from right to left.

    Type Parameters

    • A extends any[]
    • R1
    • R2
    • R3
    • R4

    Parameters

    • f4: ((a: R3) => R4)

      The function to invoke.

        • (a): R4
        • Parameters

          Returns R4

    • f3: ((a: R2) => R3)

      The function to invoke.

        • (a): R3
        • Parameters

          Returns R3

    • f2: ((a: R1) => R2)

      The function to invoke.

        • (a): R2
        • Parameters

          Returns R2

    • f1: ((...args: A) => R1)

      The function to invoke.

        • (...args): R1
        • Parameters

          • Rest...args: A

          Returns R1

    Returns ((...args: A) => R4)

    Returns the new composite function.

      • (...args): R4
      • Parameters

        • Rest...args: A

        Returns R4

    const add = (x: number, y: number) => x + y;
    const square = (n: number) => n * n;
    const double = (n: number) => n * 2;
    const toStr = (n: number) => n.toString();

    const combined = flowRight(toStr, double, square, add);
    console.log(combined(1, 2)); // '18'
  • Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

    The this context of the returned function is also passed to the functions provided as parameters.

    This method is like flow except that it creates a function that invokes the given functions from right to left.

    Type Parameters

    • A extends any[]
    • R1
    • R2
    • R3
    • R4
    • R5

    Parameters

    • f5: ((a: R4) => R5)

      The function to invoke.

        • (a): R5
        • Parameters

          Returns R5

    • f4: ((a: R3) => R4)

      The function to invoke.

        • (a): R4
        • Parameters

          Returns R4

    • f3: ((a: R2) => R3)

      The function to invoke.

        • (a): R3
        • Parameters

          Returns R3

    • f2: ((a: R1) => R2)

      The function to invoke.

        • (a): R2
        • Parameters

          Returns R2

    • f1: ((...args: A) => R1)

      The function to invoke.

        • (...args): R1
        • Parameters

          • Rest...args: A

          Returns R1

    Returns ((...args: A) => R5)

    Returns the new composite function.

      • (...args): R5
      • Parameters

        • Rest...args: A

        Returns R5

    const add = (x: number, y: number) => x + y;
    const square = (n: number) => n * n;
    const double = (n: number) => n * 2;
    const toStr = (n: number) => n.toString();
    const split = (s: string) => s.split('');

    const combined = flowRight(split, toStr, double, square, add);
    console.log(combined(1, 2)); // ['1', '8']
  • Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.

    The this context of the returned function is also passed to the functions provided as parameters.

    This method is like flow except that it creates a function that invokes the given functions from right to left.

    Parameters

    • Rest...funcs: ((...args: any[]) => any)[]

      The functions to invoke.

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

    Returns the new composite function.

      • (...args): any
      • Parameters

        • Rest...args: any[]

        Returns any

    const add = (x: number, y: number) => x + y;
    const square = (n: number) => n * n;

    const combined = flowRight(square, add);
    console.log(combined(1, 2)); // 9