Using `Option` as an `Effect` and managing the transition between `Option` and `Effect` is a comm...

Hello fine effect folk. I've been excessively making use of the fact that Option is an
Effect
, and flat-mapping it all over the place for convenience, which effectively moves the none to the error channel of the
Effect
.

Sometimes, however, I want the value to remain an Option. I've been using something like this to re-map it:
const mapToOption = <A, E extends never, R>(
    that: Effect.Effect<A, NoSuchElementException | E, R>,
): Effect.Effect<Option.Option<A>, E, R> =>
    that.pipe(
        Effect.map(Option.some),
        Effect.catchTag('NoSuchElementException', () =>
            Effect.succeed(Option.none()),
        ),
    );

// example
declare const f: (n: number) => Effect.Effect<number>;
const option = Option.some(24);
option.pipe(Effect.flatMap(f), mapToOption) // Effect<Option<number>>


Two questions here:
1. Am I doing something unconventional, if so, what would be a better way to express this?
2. Are there built-in combinators that I am missing? Effect.option kinda does that, but aggressively maps all errors (not what I need).
Was this page helpful?