@vsokolov/utils - v0.32.0
    Preparing search index...

    Function pipe

    • Composes functions from left to right, passing the result of each function to the next.

      Type Parameters

      • FirstFn extends AnyFunc<unknown[], unknown>

        The first function in the pipeline

      • F extends AnyFunc<unknown[], unknown>[]

        Array of subsequent functions to compose

      Parameters

      • arg: ParametersOf<FirstFn>[0]

        Initial value to pass to the first function (omit if first function takes no arguments)

      • firstFn: FirstFn

        The first function to execute (or can be the only argument if it takes no parameters)

      • ...fns: F

        Additional functions to compose, where each function receives the return value of the previous function

      Returns LastFnReturnType<F, ReturnType<FirstFn>>

      The return value of the last function in the pipeline

      With initial argument
      const addTwo = (x: number) => x + 2;
      const multiplyByThree = (x: number) => x * 3;
      pipe(5, addTwo, multiplyByThree); // Returns 21: (5 + 2) * 3
      Without initial argument (first function takes no parameters)
      const getValue = () => 10;
      const double = (x: number) => x * 2;
      pipe(getValue, double); // Returns 20
    • Composes functions from left to right, passing the result of each function to the next.

      Type Parameters

      • FirstFn extends () => unknown

        The first function in the pipeline

      • F extends AnyFunc<unknown[], unknown>[]

        Array of subsequent functions to compose

      Parameters

      • firstFn: FirstFn

        The first function to execute (or can be the only argument if it takes no parameters)

      • ...fns: F

        Additional functions to compose, where each function receives the return value of the previous function

      Returns LastFnReturnType<F, ReturnType<FirstFn>>

      The return value of the last function in the pipeline

      With initial argument
      const addTwo = (x: number) => x + 2;
      const multiplyByThree = (x: number) => x * 3;
      pipe(5, addTwo, multiplyByThree); // Returns 21: (5 + 2) * 3
      Without initial argument (first function takes no parameters)
      const getValue = () => 10;
      const double = (x: number) => x * 2;
      pipe(getValue, double); // Returns 20