Converting `Option<Effect<A, E, R>>` to `Effect<Option<A>, E, R>` in TypeScript

Anyone know a function that turns Option<Effect<A, E, R>> to Effect<Option<A>, E, R> ? Typical use case:

const maybeId = Option.some("user_1234");

maybeId.map(id => Effect.tryPromise(() => fetch(`/${id}`)) // now I have Option<Effect<User, UnknownException, never>> and I want Effect<Option<User>, UnknownException, never>


I have considered flatten the Effect so I will have Effect<User, UnknownException | NoSuchElementException> but that is not good because, if tryPromise returns a NoSucheElement, I won't know if this is because tryPromise failed or maybeId that is None
Was this page helpful?