import { JsonOption, JsonResult, LooseRecord } from "./types"; declare class __Option { static P: { Some: (value: A_1) => { readonly tag: "Some"; readonly value: A_1; }; None: { readonly tag: "None"; }; }; static Some: (value: A_1) => Option; static None: () => Option; static isOption: (value: unknown) => value is Option; /** * Create an Option from a nullable value */ static fromNullable: (nullable: A_1 | null | undefined) => Option; /** * Create an Option from a value | null */ static fromNull: (nullable: A_1 | null) => Option; /** * Create an Option from a undefined | value */ static fromUndefined: (nullable: A_1 | undefined) => Option; /** * Create an Option from a value & predicate */ static fromPredicate(value: A, predicate: (value: A) => value is B): Option; static fromPredicate(value: A, predicate: (value: A) => boolean): Option; /** * Turns an array of options into an option of array */ static all: []>(options: Options) => Option<{ [K in keyof Options]: Options[K] extends Option ? T : never; }>; /** * Turns an dict of options into a options of dict */ static allFromDict: >>(dict: Dict) => Option<{ [K in keyof Dict]: Dict[K] extends Option ? T : never; }>; static equals: (a: Option, b: Option, equals: (a: A_1, b: A_1) => boolean) => boolean; static fromJSON: (value: JsonOption) => Some | None; /** * Returns the Option containing the value from the callback * * (Option\, A => B) => Option\ */ map(this: Option, func: (value: A) => B): Option; /** * Returns the Option containing the value from the callback * * (Option\, A => Option\) => Option\ */ flatMap(this: Option, func: (value: A) => Option): Option; /** * Returns the Option if its value matches the predicate, otherwise false * * (Option\, A => boolean) => Option\ */ filter(this: Option, func: (value: A) => value is B): Option; filter(this: Option, func: (value: A) => boolean): Option; /** * Returns the value. Use within `if (Option.isSome()) { ... }` */ get(this: Some): A; /** * Return the value if present, and the fallback otherwise * * (Option\, A) => A * @deprecated */ getWithDefault(this: Option, defaultValue: A): A; /** * Return the value if present, and the fallback otherwise * * (Option\, A) => A */ getOr(this: Option, defaultValue: A): A; /** * Return the value if present, and the fallback otherwise * * (Option\, Option\) => Option\ */ orElse(this: Option, other: Option): Option; /** * Maps the value if present, returns the fallback otherwise * * (Option\, B, A => B) => B */ mapOr(this: Option, defaultValue: B, mapper: (value: A) => B): B; /** * Explodes the Option given its case */ match(this: Option, config: { Some: (value: A) => B1; None: () => B2; }): B1 | B2; /** * Runs the callback and returns `this` */ tap(this: Option, func: (option: Option) => unknown): Option; /** * Runs the callback if some and returns `this` */ tapSome(this: Option, func: (option: A) => unknown): Option; /** * Converts the Option\ to a `A | undefined` */ toUndefined(this: Option): A | undefined; /** * Converts the Option\ to a `A | null` */ toNull(this: Option): A | null; /** * Takes the option and turns it into Ok(value) is Some, or Error(valueWhenNone) */ toResult(this: Option, valueWhenNone: E): Result; /** * Typeguard */ isSome(this: Option): this is Some; /** * Typeguard */ isNone(this: Option): this is None; toJSON(this: Option): JsonOption; } interface Some extends __Option { readonly tag: "Some"; readonly value: A; } interface None extends __Option { readonly tag: "None"; } export declare const Option: typeof __Option; export type Option = Some | None; declare class __Result { static P: { Ok: (value: A_1) => { readonly tag: "Ok"; readonly value: A_1; }; Error: (error: E_1) => { readonly tag: "Error"; readonly error: E_1; }; }; static Ok: (value: A_1) => Result; static Error: (error: E_1) => Result; static isResult: (value: unknown) => value is Result; /** * Runs the function and resolves a result of its return value, or to an error if thrown */ static fromExecution: (func: () => A_1) => Result; /** * Takes the promise and resolves a result of its value, or to an error if rejected */ static fromPromise: (promise: Promise) => Promise>; /** * Takes the option and turns it into Ok(value) is Some, or Error(valueWhenNone) */ static fromOption: (option: Option, valueWhenNone: E_1) => Result; /** * Turns an array of results into an result of array */ static all: []>(results: Results) => Result<{ [K in keyof Results]: Results[K] extends Result ? T : never; }, { [K_1 in keyof Results]: Results[K_1] extends Result ? T_1 : never; }[number]>; /** * Turns an dict of results into a results of dict */ static allFromDict: >>(dict: Dict) => Result<{ [K in keyof Dict]: Dict[K] extends Result ? T : never; }, { [K_1 in keyof Dict]: Dict[K_1] extends Result ? T_1 : never; }[keyof Dict]>; static equals: (a: Result, b: Result, equals: (a: A_1, b: A_1) => boolean) => boolean; static fromJSON: (value: JsonResult) => Result; /** * Returns the Result containing the value from the callback * * (Result\, A => B) => Result\ */ map(this: Result, func: (value: A) => B): Result; /** * Returns the Result containing the error returned from the callback * * (Result\, E => F) => Result\ */ mapError(this: Result, func: (value: E) => F): Result; /** * Returns the Result containing the value from the callback * * (Result\, A => Result\) => Result\ */ flatMap(this: Result, func: (value: A) => Result): Result; /** * Returns the Result containing the value from the callback * * (Result\, E => Result\) => Result\ */ flatMapError(this: Result, func: (value: E) => Result): Result; /** * Returns the value. Use within `if (result.isOk()) { ... }` */ get(this: Ok): A; /** * Returns the error. Use within `if (result.isError()) { ... }` */ getError(this: Error): E; /** * Return the value if present, and the fallback otherwise * * (Result\, A) => A * @deprecated */ getWithDefault(this: Result, defaultValue: A): A; /** * Return the value if present, and the fallback otherwise * * (Result\, A) => A */ getOr(this: Result, defaultValue: A): A; /** * Maps the value if present, returns the fallback otherwise * * (Result\, B, A => B) => B */ mapOr(this: Result, defaultValue: B, mapper: (value: A) => B): B; /** * Explodes the Result given its case */ match(this: Result, config: { Ok: (value: A) => B1; Error: (error: E) => B2; }): B1 | B2; /** * Runs the callback and returns `this` */ tap(this: Result, func: (result: Result) => unknown): Result; /** * Runs the callback if ok and returns `this` */ tapOk(this: Result, func: (value: A) => unknown): Result; /** * Runs the callback if error and returns `this` */ tapError(this: Result, func: (error: E) => unknown): Result; /** * Return an option of the value * * (Result\) => Option\ */ toOption(this: Result): Option; /** * Typeguard */ isOk(this: Result): this is Ok; /** * Typeguard */ isError(this: Result): this is Error; toJSON(this: Result): JsonResult; } interface Ok extends __Result { readonly tag: "Ok"; readonly value: A; } interface Error extends __Result { readonly tag: "Error"; readonly error: E; } export declare const Result: typeof __Result; export type Result = Ok | Error; export {};