export interface Maybe { isJust(): this is Just; } export type Just = Maybe & { get(): T }; export function just(value: T): Just { return { isJust: () => true, get: () => value }; } export function nothing(): Maybe { return { isJust: () => false, }; }