# Result API Surface These are ALL available methods for Result. Do not use any method not listed here. ## Types ```typescript type Result = Ok | Err type ResultPromise = Promise> type OkPromise = Promise> type ErrPromise = Promise> type ResultPartitionResult = { values: T[]; errors: E[] } ``` ## Factory Functions ```typescript function ok(value: T): Ok function err(error: E): Err ``` ## Ok Instance Methods ```typescript class Ok { readonly value: T isOk(): this is Ok isErr(): this is never map(fn: (value: T) => U): Ok mapErr(fn: (error: never) => F): Ok flatMap>(fn: (value: T) => R): R flatMapErr(): this match(onOk: (value: T) => U, onErr: (error: never) => U): U // Overload 1: type-narrowing predicate filter(predicate: (value: T) => value is U, errorFactory: (value: T) => F): Ok | Err // Overload 2: boolean predicate filter(predicate: (value: T) => boolean, errorFactory: (value: T) => F): Ok | Err toNullable(): T toUndefined(): T toString(): string } ``` ## Err Instance Methods ```typescript class Err { readonly err: E isOk(): this is never isErr(): this is Err map(): Err mapErr(fn: (error: E) => F): Err flatMap(): this flatMapErr>(fn: (error: E) => R): R match(onOk: (value: never) => U, onErr: (error: E) => U): U filter(): Err toNullable(): null toUndefined(): undefined toString(): string } ``` ## Result Namespace (Static Methods) ```typescript Result.from(fn: () => T, errorMap?: (error: unknown) => E): Result Result.isResult(value: unknown): value is Result Result.all(results: Ok[]): Ok Result.all(results: Result[]): Result Result.partition(results: Result[]): ResultPartitionResult Result.compact(results: Result[]): T[] Result.some(results: Result[]): boolean Result.every(results: Result[]): boolean ``` ## ResultPromise Namespace (Async Methods) ```typescript ResultPromise.from(fn: () => Promise, errorMap?: (error: unknown) => E): ResultPromise ResultPromise.all(promises: Promise>[]): Promise> ResultPromise.all(promises: Promise>[]): Promise> ResultPromise.partition(promises: Promise>[]): Promise> ResultPromise.compact(promises: Promise>[]): Promise ResultPromise.some(promises: Promise>[]): Promise ResultPromise.every(promises: Promise>[]): Promise ```