Result Type — react Architecture
Architecture documentation for the Result type/interface in Result.ts from the react codebase.
Entity Profile
Dependency Diagram
graph TD 7aace723_0ee1_cff5_b263_aec8e06dd79e["Result"] 494e3425_0b47_293a_1ea4_d4670b0fc0e7["Result.ts"] 7aace723_0ee1_cff5_b263_aec8e06dd79e -->|defined in| 494e3425_0b47_293a_1ea4_d4670b0fc0e7 style 7aace723_0ee1_cff5_b263_aec8e06dd79e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
compiler/packages/babel-plugin-react-compiler/src/Utils/Result.ts lines 9–86
export interface Result<T, E> {
/*
* Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a contained `Ok` value,
* leaving an `Err` value untouched.
*
* This function can be used to compose the results of two functions.
*/
map<U>(fn: (val: T) => U): Result<U, E>;
/*
* Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a contained `Err` value,
* leaving an `Ok` value untouched.
*
* This function can be used to pass through a successful result while handling an error.
*/
mapErr<F>(fn: (val: E) => F): Result<T, F>;
/*
* Returns the provided default (if `Err`), or applies a function to the contained value
* (if `Ok`).
*
* Arguments passed to {@link mapOr} are eagerly evaluated; if you are passing the result of a
* function call, it is recommended to use {@link mapOrElse}, which is lazily evaluated.
*/
mapOr<U>(fallback: U, fn: (val: T) => U): U;
/*
* Maps a `Result<T, E>` to `U` by applying fallback function default to a contained `Err` value,
* or function `fn` to a contained `Ok` value.
*
* This function can be used to unpack a successful result while handling an error.
*/
mapOrElse<U>(fallback: () => U, fn: (val: T) => U): U;
/*
* Calls `fn` if the result is `Ok`, otherwise returns the `Err` value of self.
*
* This function can be used for control flow based on Result values.
*/
andThen<U>(fn: (val: T) => Result<U, E>): Result<U, E>;
/*
* Returns res if the result is `Ok`, otherwise returns the `Err` value of self.
*
* Arguments passed to {@link and} are eagerly evaluated; if you are passing the result of a
* function call, it is recommended to use {@link andThen}, which is lazily evaluated.
*/
and<U>(res: Result<U, E>): Result<U, E>;
/*
* Returns `res` if the result is `Err`, otherwise returns the `Ok` value of self.
*
* Arguments passed to {@link or} are eagerly evaluated; if you are passing the result of a
* function call, it is recommended to use {@link orElse}, which is lazily evaluated.
*/
or(res: Result<T, E>): Result<T, E>;
/*
* Calls `fn` if the result is `Err`, otherwise returns the `Ok` value of self.
*
* This function can be used for control flow based on result values.
*/
orElse<F>(fn: (val: E) => Result<T, F>): Result<T, F>;
// Returns `true` if the result is `Ok`.
isOk(): this is OkImpl<T>;
// Returns `true` if the result is `Err`.
isErr(): this is ErrImpl<E>;
// Returns the contained `Ok` value or throws.
expect(msg: string): T;
// Returns the contained `Err` value or throws.
expectErr(msg: string): E;
// Returns the contained `Ok` value.
unwrap(): T;
/*
* Returns the contained `Ok` value or a provided default.
*
* Arguments passed to {@link unwrapOr} are eagerly evaluated; if you are passing the result of a
* function call, it is recommended to use {@link unwrapOrElse}, which is lazily evaluated.
*/
unwrapOr(fallback: T): T;
// Returns the contained `Ok` value or computes it from a closure.
unwrapOrElse(fallback: (val: E) => T): T;
// Returns the contained `Err` value or throws.
unwrapErr(): E;
}
Source
Frequently Asked Questions
What is the Result type?
Result is a type/interface in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/src/Utils/Result.ts.
Where is Result defined?
Result is defined in compiler/packages/babel-plugin-react-compiler/src/Utils/Result.ts at line 9.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free