Effect CommunityEC
Effect Communityβ€’2y agoβ€’
10 replies
giacomo

Type narrowing on `yield*` early-return

One thing I appreciate about Effect.gen is "early return" by yielding an error. Eg.
const maybeValue = ...;
if (Option.isNone(maybeValue)) yield* new ErrorXYZ();
// this is not executed

This is great, specially coming from fp-ts where Option.match forced the indentation of the main path under onSome.

I'm wondering about the best way to go about this. Specifically maybeValue above is not narrowed to Option.Some<...>, its type is Option.Option<...>. I've found a few alternatives but none I'm fully satisfied with.
Was this page helpful?