FuncType - v0.16.0
    Preparing search index...

    Function DoAsync

    • Executes an async generator-based monadic comprehension Returns the same monad type as the first yielded monad

      Type Parameters

      • T

      Parameters

      • gen: () => AsyncGenerator<OptionLike, T, unknown>

        Async generator function that yields monads/promises and returns a result

      Returns Promise<Option<T>>

      Promise of the same monad type as first yield

      const result = await DoAsync(async function* () {
      const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
      const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
      return { user, profile };
      });
      // result type matches first yield
    • Executes an async generator-based monadic comprehension Returns the same monad type as the first yielded monad

      Type Parameters

      • L
      • R

      Parameters

      • gen: () => AsyncGenerator<EitherLike, R, unknown>

        Async generator function that yields monads/promises and returns a result

      Returns Promise<Either<L, R>>

      Promise of the same monad type as first yield

      const result = await DoAsync(async function* () {
      const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
      const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
      return { user, profile };
      });
      // result type matches first yield
    • Executes an async generator-based monadic comprehension Returns the same monad type as the first yielded monad

      Type Parameters

      • T

      Parameters

      • gen: () => AsyncGenerator<ListLike, T, unknown>

        Async generator function that yields monads/promises and returns a result

      Returns Promise<List<T>>

      Promise of the same monad type as first yield

      const result = await DoAsync(async function* () {
      const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
      const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
      return { user, profile };
      });
      // result type matches first yield
    • Executes an async generator-based monadic comprehension Returns the same monad type as the first yielded monad

      Type Parameters

      • T

      Parameters

      • gen: () => AsyncGenerator<TryLike, T, unknown>

        Async generator function that yields monads/promises and returns a result

      Returns Promise<Try<T>>

      Promise of the same monad type as first yield

      const result = await DoAsync(async function* () {
      const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
      const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
      return { user, profile };
      });
      // result type matches first yield
    • Executes an async generator-based monadic comprehension Returns the same monad type as the first yielded monad

      Type Parameters

      • T

      Parameters

      • gen: () => AsyncGenerator<OptionLike | EitherLike | ListLike | TryLike, T, unknown>

        Async generator function that yields monads/promises and returns a result

      Returns Promise<Reshapeable<T>>

      Promise of the same monad type as first yield

      const result = await DoAsync(async function* () {
      const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
      const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
      return { user, profile };
      });
      // result type matches first yield
    • Executes an async generator-based monadic comprehension Returns the same monad type as the first yielded monad

      Type Parameters

      • T

      Parameters

      • gen: () => AsyncGenerator<unknown, T, unknown>

        Async generator function that yields monads/promises and returns a result

      Returns Promise<unknown>

      Promise of the same monad type as first yield

      const result = await DoAsync(async function* () {
      const user = yield* $(await fetchUser(id)); // Promise<Option<User>> → User
      const profile = yield* $(await getProfile(user)); // Promise<Either<Error, Profile>> → Profile
      return { user, profile };
      });
      // result type matches first yield