plainfp - v0.1.0
    Preparing search index...

    Function fromPromise

    • Convert a Promise<T> into a ResultAsync. Rejection is captured and passed through onError — the error type is entirely user-controlled, so pick a domain-specific shape rather than leaking unknown.

      Type Parameters

      • T
      • E

      Parameters

      • promise: Promise<T>
      • onError: (cause: unknown) => E

      Returns ResultAsyncType<T, E>

      const fetchUser = (id: string) =>
      fromPromise(
      fetch(`/users/${id}`).then(r => r.json() as Promise<User>),
      (cause) => ({ code: "FETCH_FAILED", cause }),
      )