@vgerbot/async
    Preparing search index...

    Function compose

    • Composes async functions from right to left (mathematical composition). The rightmost function is called first, and its result is passed to the next function.

      Type Parameters

      • T1
      • T2

      Parameters

      • fn1: AsyncFunction<T1, T2>

      Returns (input: T1, options?: CancellableOptions<unknown>) => CancellableHandle<T2>

      A composed function that executes all functions in sequence.

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

      const composed = compose(square, double, addOne);
      const handle = composed(5); // ((5 + 1) * 2) ^ 2 = 144
      const result = await handle; // 144
    • Composes async functions from right to left (mathematical composition). The rightmost function is called first, and its result is passed to the next function.

      Type Parameters

      • T1
      • T2
      • T3

      Parameters

      • fn2: AsyncFunction<T2, T3>
      • fn1: AsyncFunction<T1, T2>

      Returns (input: T1, options?: CancellableOptions<unknown>) => CancellableHandle<T3>

      A composed function that executes all functions in sequence.

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

      const composed = compose(square, double, addOne);
      const handle = composed(5); // ((5 + 1) * 2) ^ 2 = 144
      const result = await handle; // 144
    • Composes async functions from right to left (mathematical composition). The rightmost function is called first, and its result is passed to the next function.

      Type Parameters

      • T1
      • T2
      • T3
      • T4

      Parameters

      • fn3: AsyncFunction<T3, T4>
      • fn2: AsyncFunction<T2, T3>
      • fn1: AsyncFunction<T1, T2>

      Returns (input: T1, options?: CancellableOptions<unknown>) => CancellableHandle<T4>

      A composed function that executes all functions in sequence.

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

      const composed = compose(square, double, addOne);
      const handle = composed(5); // ((5 + 1) * 2) ^ 2 = 144
      const result = await handle; // 144
    • Composes async functions from right to left (mathematical composition). The rightmost function is called first, and its result is passed to the next function.

      Type Parameters

      • T1
      • T2
      • T3
      • T4
      • T5

      Parameters

      • fn4: AsyncFunction<T4, T5>
      • fn3: AsyncFunction<T3, T4>
      • fn2: AsyncFunction<T2, T3>
      • fn1: AsyncFunction<T1, T2>

      Returns (input: T1, options?: CancellableOptions<unknown>) => CancellableHandle<T5>

      A composed function that executes all functions in sequence.

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

      const composed = compose(square, double, addOne);
      const handle = composed(5); // ((5 + 1) * 2) ^ 2 = 144
      const result = await handle; // 144