Skip to content

Commit

Permalink
docs: more doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
N8Brooks committed Oct 31, 2024
1 parent 9ddcf96 commit 025ebf4
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/** `Result` is a type that represents either success (`Ok`) or failure (`Err`). */
export type Result<T, E> = Result.Ok<T> | Result.Err<E>;

/** A namespace to simulate `static` methods for the `Result` type. */
// deno-lint-ignore no-namespace
export namespace Result {
/**
Expand Down Expand Up @@ -226,14 +224,25 @@ export namespace Result {
return new Ok(this.ok);
}
}

interface InnerOk<T> {
/**
* Implemented by `Ok` values which contains the `ok` value.
*
* @typeParam `T`, the type of the `ok` value.
*
* @sealed Not meant to be implemented or extended by users.
*/
export interface InnerOk<T> {
/**
* Access `T | undefined` from `Result<T, E>`.
*
* @remarks doesn't work well will optional `T` types.
*/
readonly ok: T;
/**
* Access `E | undefined` from `Result<T, E>`.
*
* @remarks doesn't work well will optional `E` types.
*/
readonly err?: never;
}

Expand Down Expand Up @@ -408,7 +417,19 @@ export namespace Result {
}
}

interface InnerErr<E> {
/**
* Implemented by `Err` values which contain the `err` value.
*
* @typeParam `E`, the type of the `err` value.
*
* @sealed Not meant to be implemented or extended by users.
*/
export interface InnerErr<E> {
/**
* Access `T | undefined` from `Result<T, E>`.
*
* @remarks doesn't work well will optional `T` types.
*/
readonly ok?: never;
/**
* Access `E | undefined` from `Result<T, E>`.
Expand All @@ -418,7 +439,15 @@ export namespace Result {
readonly err: E;
}

interface Resultable<T, E> extends Iterable<T> {
/**
* The common `interface` for `Ok` and `Err` values.
*
* @typeParam `T`, the type of the `ok` value.
* @typeParam `E`, the type of the `err` value.
*
* @sealed Not meant to be implemented or extended by users.
*/
export interface Resultable<T, E> extends Iterable<T> {
[Symbol.iterator](): IterableIterator<T | never>;

/**
Expand Down Expand Up @@ -1266,3 +1295,6 @@ export namespace Result {
clone(): Result<T, E>;
}
}

/** `Result` is a type that represents either success (`Ok`) or failure (`Err`). */
export type Result<T, E> = Result.Ok<T> | Result.Err<E>;

0 comments on commit 025ebf4

Please sign in to comment.