Function compose

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: I

          Returns R

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A1

          Returns R

    • f2: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A2

          Returns R

    • f2: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f3: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • A3

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A3

          Returns R

    • f2: ((_) => A3)
        • (_): A3
        • Parameters

          • _: A2

          Returns A3

    • f3: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f4: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • A3

    • A4

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A4

          Returns R

    • f2: ((_) => A4)
        • (_): A4
        • Parameters

          • _: A3

          Returns A4

    • f3: ((_) => A3)
        • (_): A3
        • Parameters

          • _: A2

          Returns A3

    • f4: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f5: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • A3

    • A4

    • A5

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A5

          Returns R

    • f2: ((_) => A5)
        • (_): A5
        • Parameters

          • _: A4

          Returns A5

    • f3: ((_) => A4)
        • (_): A4
        • Parameters

          • _: A3

          Returns A4

    • f4: ((_) => A3)
        • (_): A3
        • Parameters

          • _: A2

          Returns A3

    • f5: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f6: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • A3

    • A4

    • A5

    • A6

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A6

          Returns R

    • f2: ((_) => A6)
        • (_): A6
        • Parameters

          • _: A5

          Returns A6

    • f3: ((_) => A5)
        • (_): A5
        • Parameters

          • _: A4

          Returns A5

    • f4: ((_) => A4)
        • (_): A4
        • Parameters

          • _: A3

          Returns A4

    • f5: ((_) => A3)
        • (_): A3
        • Parameters

          • _: A2

          Returns A3

    • f6: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f7: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • A3

    • A4

    • A5

    • A6

    • A7

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A7

          Returns R

    • f2: ((_) => A7)
        • (_): A7
        • Parameters

          • _: A6

          Returns A7

    • f3: ((_) => A6)
        • (_): A6
        • Parameters

          • _: A5

          Returns A6

    • f4: ((_) => A5)
        • (_): A5
        • Parameters

          • _: A4

          Returns A5

    • f5: ((_) => A4)
        • (_): A4
        • Parameters

          • _: A3

          Returns A4

    • f6: ((_) => A3)
        • (_): A3
        • Parameters

          • _: A2

          Returns A3

    • f7: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f8: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • A3

    • A4

    • A5

    • A6

    • A7

    • A8

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A8

          Returns R

    • f2: ((_) => A8)
        • (_): A8
        • Parameters

          • _: A7

          Returns A8

    • f3: ((_) => A7)
        • (_): A7
        • Parameters

          • _: A6

          Returns A7

    • f4: ((_) => A6)
        • (_): A6
        • Parameters

          • _: A5

          Returns A6

    • f5: ((_) => A5)
        • (_): A5
        • Parameters

          • _: A4

          Returns A5

    • f6: ((_) => A4)
        • (_): A4
        • Parameters

          • _: A3

          Returns A4

    • f7: ((_) => A3)
        • (_): A3
        • Parameters

          • _: A2

          Returns A3

    • f8: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f9: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

  • Composes given functions (in the mathematical sense).

    Unlike flow and pipe, functions passed to compose are applied (called) from last to first.

    const f = (x: number): number => x * x;
    const g = (x: number): string => x.toFixed();
    const h = (x: string): boolean => x === '4';

    compose(
    h, // 3. true
    g, // 2. 4
    f, // 1. 2
    )(2) // 4. true

    // gives same result as
    h(g(f(2))) // true

    Type Parameters

    • I

    • A1

    • A2

    • A3

    • A4

    • A5

    • A6

    • A7

    • A8

    • A9

    • R

    Parameters

    • f1: ((_) => R)
        • (_): R
        • Parameters

          • _: A9

          Returns R

    • f2: ((_) => A9)
        • (_): A9
        • Parameters

          • _: A8

          Returns A9

    • f3: ((_) => A8)
        • (_): A8
        • Parameters

          • _: A7

          Returns A8

    • f4: ((_) => A7)
        • (_): A7
        • Parameters

          • _: A6

          Returns A7

    • f5: ((_) => A6)
        • (_): A6
        • Parameters

          • _: A5

          Returns A6

    • f6: ((_) => A5)
        • (_): A5
        • Parameters

          • _: A4

          Returns A5

    • f7: ((_) => A4)
        • (_): A4
        • Parameters

          • _: A3

          Returns A4

    • f8: ((_) => A3)
        • (_): A3
        • Parameters

          • _: A2

          Returns A3

    • f9: ((_) => A2)
        • (_): A2
        • Parameters

          • _: A1

          Returns A2

    • f10: ((_) => A1)
        • (_): A1
        • Parameters

          • _: I

          Returns A1

    Returns ((x) => R)

      • (x): R
      • Parameters

        • x: I

        Returns R

Generated using TypeDoc