grill-blog/utils.ts

17 lines
573 B
TypeScript
Raw Permalink Normal View History

2024-05-13 22:50:54 +01:00
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 _;