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>>
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>>