Обзор
functionCore Result

unwrapOr

Returns the success value or a fallback.

Signature

tsSignature
export function unwrapOr<T, E>(result: Result<T, E>, fallback: T): T;

Imports

tsImport
import { unwrapOr } from "@/lib/flow/core/result";
import { unwrapOr } from "@/lib/flow";

Type Parameters

T

Success value type.

E

Expected error value type.

Parameters

result
Result<T, E>

Result to read.

fallback
T

Value returned when the result failed.

Returns

The success value or fallback.

Return type
T

Details

Use this when a failure can be safely collapsed into a default value.

Examples

tsExample
const count = unwrapOr(result, 0);
Result

Explicit success-or-failure outcome used throughout Flow.

type
when

Branches between two behaviors using a predicate function.

function

Source

tsflow/core/result.ts:200-202
export function unwrapOr<T, E>(result: Result<T, E>, fallback: T): T {
return result.ok ? result.value : fallback;
}