| 1 | import * as Exit from "../../Exit.ts" |
| 2 | import * as Option from "../../Option.ts" |
| 3 | import { args } from "../core.ts" |
| 4 | |
| 5 | /** @internal */ |
| 6 | export const missing = Symbol() |
| 7 | |
| 8 | /** @internal */ |
| 9 | export { args } |
| 10 | |
| 11 | /** @internal */ |
| 12 | export type Success<A, E = never> = Exit.Success<A, E> & { readonly [args]: A } |
| 13 | |
| 14 | /** @internal */ |
| 15 | export const succeed = Exit.succeed as <A>(value: A) => Success<A> |
| 16 | |
| 17 | /** @internal */ |
| 18 | export const missingExit = succeed(missing) |
| 19 | |
| 20 | // Shared success for a present input returned unchanged. It must be resolved |
| 21 | // before crossing an asynchronous or transformation boundary. |
| 22 | /** @internal */ |
| 23 | export const sameExit: Success<unknown> = succeed(missing) |
| 24 | |
| 25 | /** @internal */ |
| 26 | export const toOption = <A>(value: A): Option.Option<A> => value === missing ? Option.none() : Option.some(value as A) |
| 27 | |
| 28 | /** @internal */ |
| 29 | export const fromOptionExit = <A>(option: Option.Option<A>): Success<A | typeof missing> => |
| 30 | option._tag === "None" ? missingExit : succeed(option.value) |