Function withCustomAdapter

  • Creates a curried function that takes an input value of type T and returns an async iterable based on the provided adapter function.

    Returns

    A function that takes an input value of type T and returns an AsyncIterable of U.

    Example

    const arrayAdapter: Adapter<number[], number> = (array) => {
    let index = 0;
    return {
    next: () =>
    Promise.resolve(
    index < array.length
    ? { value: array[index++], done: false }
    : { value: undefined, done: true }
    ),
    };
    };
    const iterable = withCustomAdapter(arrayAdapter)([1, 2, 3]);

    (async () => {
    for await (const value of iterable) {
    console.log(value); // Logs 1, 2, 3
    }
    })();

    Type Parameters

    • T

      The type of input value.

    • U

      The type of data contained in the resulting async iterable.

    Parameters

    • adapter: Adapter<T, U>

      The adapter function to transform the input value into an async iterable.

    Returns ((input: T) => AsyncIterable<U>)

      • (input: T): AsyncIterable<U>
      • Parameters

        • input: T

        Returns AsyncIterable<U>

Generated using TypeDoc