TS-Scribe - v1.2.0
    Preparing search index...

    Function asyncPipe

    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Returns <T>(x: T) => Promise<T>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }
    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Type Parameters

      • A
      • B

      Parameters

      • f1: (x: A) => B | Promise<B>

      Returns (x: A) => Promise<B>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }
    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Type Parameters

      • A
      • B
      • C

      Parameters

      • f1: (x: A) => B | Promise<B>
      • f2: (x: B) => C | Promise<C>

      Returns (x: A) => Promise<C>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }
    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Type Parameters

      • A
      • B
      • C
      • D

      Parameters

      • f1: (x: A) => B | Promise<B>
      • f2: (x: B) => C | Promise<C>
      • f3: (x: C) => D | Promise<D>

      Returns (x: A) => Promise<D>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }
    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Type Parameters

      • A
      • B
      • C
      • D
      • E

      Parameters

      • f1: (x: A) => B | Promise<B>
      • f2: (x: B) => C | Promise<C>
      • f3: (x: C) => D | Promise<D>
      • f4: (x: D) => E | Promise<E>

      Returns (x: A) => Promise<E>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }
    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Type Parameters

      • A
      • B
      • C
      • D
      • E
      • F

      Parameters

      • f1: (x: A) => B | Promise<B>
      • f2: (x: B) => C | Promise<C>
      • f3: (x: C) => D | Promise<D>
      • f4: (x: D) => E | Promise<E>
      • f5: (x: E) => F | Promise<F>

      Returns (x: A) => Promise<F>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }
    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Type Parameters

      • A
      • B
      • C
      • D
      • E
      • F
      • G

      Parameters

      • f1: (x: A) => B | Promise<B>
      • f2: (x: B) => C | Promise<C>
      • f3: (x: C) => D | Promise<D>
      • f4: (x: D) => E | Promise<E>
      • f5: (x: E) => F | Promise<F>
      • f6: (x: F) => G | Promise<G>

      Returns (x: A) => Promise<G>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }
    • Composes functions from left to right, threading the resolved return value of each function as the argument to the next. Each function may be sync or async — the result is always a Promise.

      For sync-only composition, see pipe.

      Parameters

      • ...fns: ((x: any) => any)[]

        One or more functions to compose left-to-right. Each may return a plain value or a Promise.

      Returns (x: any) => Promise<any>

      An async function that passes its argument through every function in order, awaiting each step.

      // All sync functions — result is still a Promise
      const add1 = (n: number) => n + 1;
      const double = (n: number) => n * 2;
      const pipeline = asyncPipe(add1, double);

      await pipeline(3); // (3 + 1) * 2 = 8
      // All async functions
      const fetchUser = async (id: number) => ({ id, name: 'Alice' });
      const getName = async (user: { name: string }) => user.name;
      const pipeline = asyncPipe(fetchUser, getName);

      await pipeline(1); // 'Alice'
      // Mixed sync and async
      const trim = (s: string) => s.trim();
      const fetchByQuery = async (q: string) => ({ results: [q] });

      const search = asyncPipe(trim, fetchByQuery);
      await search(' hello '); // { results: ['hello'] }