import { Just } from './Just' import { Nothing } from './Nothing' export type Maybe = Just | Nothing export type MaybeOf = { [K in keyof A]: Maybe } export type MaybeValue> = A extends Maybe ? R : never export namespace Maybe { /** * Creates a Maybe containing a value. If the value is `undefined` or `null` * a `Nothing` will be returned. All other values will be wrapped in a `Just`. * @name Maybe.of(value: A): Maybe */ export const of = (value: A | null | undefined | void): Maybe => value === null || value === undefined ? Nothing : Just.of(value as A) export const fromString = (str: string | null | undefined | void): Maybe => !str ? Nothing : Just.of(str) }