1import * as Exit from "../../Exit.ts"
2import * as Option from "../../Option.ts"
3import { args } from "../core.ts"
4
5/** @internal */
6export const missing = Symbol()
7
8/** @internal */
9export { args }
10
11/** @internal */
12export type Success<A, E = never> = Exit.Success<A, E> & { readonly [args]: A }
13
14/** @internal */
15export const succeed = Exit.succeed as <A>(value: A) => Success<A>
16
17/** @internal */
18export 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 */
23export const sameExit: Success<unknown> = succeed(missing)
24
25/** @internal */
26export const toOption = <A>(value: A): Option.Option<A> => value === missing ? Option.none() : Option.some(value as A)
27
28/** @internal */
29export const fromOptionExit = <A>(option: Option.Option<A>): Success<A | typeof missing> =>
30 option._tag === "None" ? missingExit : succeed(option.value)