import type { FiberId } from "../../Fiber/FiberId"; import { isEmpty } from "./guards"; import type { Cause } from "./model"; /** * ```haskell * fail :: e -> Cause e * ``` */ export const fail = (value: E): Cause => ({ _tag: "Fail", value }); /** * ```haskell * die :: _ -> Cause Never * ``` */ export const die = (value: unknown): Cause => ({ _tag: "Die", value }); /** * ```haskell * interrupt :: FiberId -> Cause Never * ``` */ export const interrupt = (fiberId: FiberId): Cause => ({ _tag: "Interrupt", fiberId }); /** * ```haskell * then :: Cause c => (c e, c f) -> c (e | f) * ``` */ export const then = (left: Cause, right: Cause): Cause => isEmpty(left) ? right : isEmpty(right) ? left : { _tag: "Then", left, right }; /** * ```haskell * both :: Cause c => (c e, c f) -> c (e | f) * ``` */ export const both = (left: Cause, right: Cause): Cause => isEmpty(left) ? right : isEmpty(right) ? left : { _tag: "Both", left, right };