Effect CommunityEC
Effect Community3y ago
15 replies
James Birtles

Option to Effect.fail

given a function that returns an Effect<_, _, Option<T>>, i want to produce an error when the option is none and otherwise unwrap the some value. I will deal with the error later on. I came to this solution after a bit of playing around, is this a reasonable way of doing this?

const user = yield* _(
    userService.getUserByUsernameOrEmail(tenantId, usernameOrEmail),
    Effect.flatMap(Effect.orElseFail(() => new UserNotFoundError())),
);
Was this page helpful?