import { Effect, Either, pipe } from "effect";
const someUtilityFunction = () => Either.left(new Error("utility failed"));
const someUtilityEffect = () =>
pipe(Effect.succeed({}), Effect.flatMap(someUtilityFunction));
const doA = Effect.withSpan("doA")(
Effect.promise(async () => console.log("did some async A"))
);
const program = Effect.withSpan("program")(
pipe(
doA,
// Pick one or the other
Effect.flatMap(() => Effect.withSpan("wrapFunction")(someUtilityFunction())),
// Effect.flatMap(() => Effect.withSpan("wrapEffect")(someUtilityEffect()))
)
);
void Effect.runPromise(program);
import { Effect, Either, pipe } from "effect";
const someUtilityFunction = () => Either.left(new Error("utility failed"));
const someUtilityEffect = () =>
pipe(Effect.succeed({}), Effect.flatMap(someUtilityFunction));
const doA = Effect.withSpan("doA")(
Effect.promise(async () => console.log("did some async A"))
);
const program = Effect.withSpan("program")(
pipe(
doA,
// Pick one or the other
Effect.flatMap(() => Effect.withSpan("wrapFunction")(someUtilityFunction())),
// Effect.flatMap(() => Effect.withSpan("wrapEffect")(someUtilityEffect()))
)
);
void Effect.runPromise(program);