Effect CommunityEC
Effect Community2y ago
41 replies
Frederic

Conditional Use of `Effect.catchTag` in a Pipe Approach Context

Hi, what would be the best way to Effect.catchTag conditionally (depending on some parameter) using a pipe approach ?
Here is a generator approach as a reference
const getIp4 = (s: string, emptyJson: "error" | "noError") =>
  Effect.gen(function* ($) {
    const json =
      emptyJson === "noError"
        ? yield* $(
            parseJson2(s).pipe(
              Effect.catchTag("EmptyJsonError", (err) =>
                Effect.succeed({ ip: "176.1.1.1", name: "whatever" }),
              ),
            ),
          )
        : yield* $(parseJson2(s))
    const ip = yield* $(RR.get("ip")(json))
    return ip
  })
Was this page helpful?