@aappddeevv/dynamics-client-ui
Version:
## What is it? A library to help you create great dynamics applications.
86 lines (85 loc) • 3.11 kB
TypeScript
/** Type used to represent either success or failure. */
export interface IResult<T, E> {
/** Returns the value if result is `Ok`, `undefined` if `Err`. */
ok(): T | undefined;
/** Returns `true` if result is `Ok`, `false` if `Err`. */
isOk(): boolean;
/** Returns the error if result is `Err`, `undefined` if `Ok`. */
err(): E | undefined;
/** Returns `true` if result is `Err`, `false` if `Ok`. */
isErr(): boolean;
/**
* Maps an `IResult<T, E>` to `IResult<U, E>` by applying the function provided
* to a contained `Ok` value, leaving an `Err` value untouched.
*/
map<U>(op: (value: T) => U): IResult<U, E>;
/**
* Maps an `IResult<T, E>` to `IResult<T, F>` by applying the function provided
* to a contained `Err` value, leaving an `Ok` value untouched.
*/
mapErr<F>(op: (error: E) => F): IResult<T, F>;
/**
* Returns `res` if the receiver is `Ok`, otherwise returns the `Err` value of
* the receiver.
*/
and<U>(res: IResult<U, E>): IResult<U, E>;
/**
* Invokes `op` if the receiver is `Ok`, returning the result.
* If the receiver is `Err`, returns the `Err` value of the receiver.
*/
andThen<U>(op: (value: T) => IResult<U, E>): IResult<U, E>;
/**
* Unwraps the result, yielding the contents of the receiver if `Ok`.
* Throws an exception if the receiver is an `Err`.
*/
unwrap(): T;
/**
* Unwraps the result, yielding the contents of the receiver if `Err`.
* Throws an exception if the receiver is an `Ok`.
*/
unwrapErr(): E;
/**
* Unwraps a result, yielding the content if the receiver is `Ok`.
* If the receiver is an `Err`, returns `outherwise`.
*/
unwrapOr(otherwise: T): T;
/**
* Unwraps a result, yielding the content if the receiver is `Ok`.
* If the receiver is an `Err`, returns the result of invoking the parameter.
*/
unwrapOrElse(otherwise: (error: E) => T): T;
}
/** Contains the success value. */
export declare class Ok<T, E> implements IResult<T, E> {
private value;
constructor(v: T);
ok(): T | undefined;
isOk(): boolean;
err(): E | undefined;
isErr(): boolean;
map<U>(op: (value: T) => U): IResult<U, E>;
mapErr<F>(op: (error: E) => F): IResult<T, F>;
and<U>(res: IResult<U, E>): IResult<U, E>;
andThen<U>(op: (value: T) => IResult<U, E>): IResult<U, E>;
unwrap(): T;
unwrapErr(): E;
unwrapOr(otherwise: T): T;
unwrapOrElse(otherwise: (error: E) => T): T;
}
/** Contains the error value. */
export declare class Err<T, E> implements IResult<T, E> {
private value;
constructor(v: E);
ok(): T | undefined;
isOk(): boolean;
err(): E | undefined;
isErr(): boolean;
map<U>(op: (value: T) => U): IResult<U, E>;
mapErr<F>(op: (error: E) => F): IResult<T, F>;
and<U>(res: IResult<U, E>): IResult<U, E>;
andThen<U>(op: (value: T) => IResult<U, E>): IResult<U, E>;
unwrap(): T;
unwrapErr(): E;
unwrapOr(otherwise: T): T;
unwrapOrElse(otherwise: (error: E) => T): T;
}