import { Console, Effect } from "npm:effect";
const sucessfulProgram = Effect.sync(() => {
console.log("hi!");
return 42;
});
const main = Console.log("hi");
const num = Effect.succeed(2)
console.log("num effect", num);
Effect.runSync(main);
const divide = (a: number, b: number): Effect.Effect<number, Error, never> =>
b === 0
? Effect.fail(new Error("Cannot divide by zero"))
: Effect.succeed(a / b);
console.log("divide effect :", divide(10, 10));
const divisionResult = Effect.runSync(divide(10, 10));
console.log("division result :", divisionResult);
const failedProgram = Effect.try(() => {
throw new Error("boom");
return 42;
});
const asyncProgram = Effect.promise(() => Promise.resolve(42));
const result = Effect.runSync(sucessfulProgram);
console.log("runSync result", result);