import type { Either } from "../../Either"; import type { Option } from "../../Option"; import type { FiberId } from "../Fiber/FiberId"; import type { Cause } from "./Cause"; import * as C from "./Cause"; import type { Exit } from "./model"; export const succeed = (value: A): Exit => ({ _tag: "Success", value }); export const failure = (cause: Cause): Exit => ({ _tag: "Failure", cause }); export const fail = (e: E): Exit => failure(C.fail(e)); export const interrupt = (id: FiberId) => failure(C.interrupt(id)); export const die = (error: unknown): Exit => failure(C.die(error)); export const fromEither = (e: Either): Exit => (e._tag === "Left" ? fail(e.left) : succeed(e.right)); export const fromOption_ = (fa: Option, onNone: () => E): Exit => fa._tag === "None" ? fail(onNone()) : succeed(fa.value); export const fromOption = (onNone: () => E) => (fa: Option): Exit => fromOption_(fa, onNone);