Function pipe

  • Pipes multiple functions from left to right.

    Type Parameters

    • T

      The type of input and output for all functions.

    Parameters

    • Rest...fns: ((arg: T) => T)[]

      The functions to apply sequentially.

    Returns ((arg: T) => T)

    • A function that applies the piped functions from left to right.
      • (arg): T
      • Parameters

        • arg: T

        Returns T

    const trim = (s: string): string => s.trim();
    const toUpperCase = (s: string): string => s.toUpperCase();
    const exclaim = (s: string): string => `${s}!`;

    const pipedFn = pipe(trim, toUpperCase, exclaim);
    console.log(pipedFn(" hello ")); // "HELLO!"