Effect CommunityEC
Effect Community3y ago
14 replies
virgule

Implementing Early Return in TypeScript Effect

Hi 👋
I'd like to do something similar to an early return in an effect so I can check if a value is defined or not before proceeding to the rest of the operations. But I'm not sure how I could do this and narrow the input value's type similarly to an if (...) return; in typescript.
const program = pipe(
  getSettings(), // object | null

  // TODO: if (!settings.colorscheme) interupt

  Effect.flatMap(settings => {
    // similarly to an `if (...) return`, the type should be narrowed to `object`
    return applySettings(settings);
  }),
);
Was this page helpful?