Tweakr
    Preparing search index...

    Function asyncCompose

    • Composes multiple asynchronous (or synchronous) functions into a single function, executing them from right to left.

      Type Parameters

      • Input

        The input type of the composed function.

      • Output

        The final output type after all compositions.

      Parameters

      • ...fns: AsyncFn<any, any>[]

        Functions to compose, executed from right to left.

      Returns (input: Input) => Promise<Output>

      A new function that represents the asynchronous composition.

      const addOne = async (x: number) => x + 1;
      const double = async (x: number) => x * 2;

      const process = asyncCompose(double, addOne);
      await process(3); // → 8

      1.0.0