17 lines
573 B
TypeScript
17 lines
573 B
TypeScript
|
export type Ok<T> = { ok: true; value: T };
|
||
|
export type Err<E> = { ok: false; error: E };
|
||
|
export type Result<T, E> = Ok<T> | Err<E>;
|
||
|
|
||
|
export const Ok = <T>(value: T): Ok<T> => ({ ok: true, value });
|
||
|
export const Err = <E>(error: E): Err<E> => ({ ok: false, error });
|
||
|
|
||
|
export type Some<T> = { some: true; value: T };
|
||
|
export type None = { some: false };
|
||
|
export type Option<T> = Some<T> | None;
|
||
|
|
||
|
export const Some = <T>(value: T): Some<T> => ({ some: true, value });
|
||
|
export const None: None = { some: false } as const;
|
||
|
|
||
|
export const _ = Symbol("_");
|
||
|
export type _ = typeof _;
|