Effect CommunityEC
Effect Community2y ago
4 replies
bste

Modeling calling an external API with Option and Effect

Hey all. I'm trying to model calling an external API but only if I have some input data available and I'm having some trouble thinking it through with Option and Effect. I've got this so far but it looks a bit gross. Is there a better way I can express this?

const maybeGetPerson = (maybePersonId: Option.Option<PersonId>) => pipe(
    maybePersonId,
    Option.map(_ => Queries.getPerson(_).pipe(Effect.asSome)),
    Option.getOrElse(() => Effect.succeed(Option.none()))
)
Was this page helpful?