Manuscript Documentation
v0.1.0

@std/result.ms#

These names are available in the prelude; no import required.

Explicit imports of these prelude declarations are rejected; remove them from the import.

Result Alternative#

Holds either a successful value (ok) or an expected failure (error).

Manuscript
type Result[T, E]:
    case ok(value: T)
    case error(cause: E)
    fn is_ok() -> Bool:
    fn is_error() -> Bool:
    fn unwrap() -> T:
    fn unwrap_error() -> E:
    fn unwrap_or(fallback: T) -> T:
    fn unwrap_or_else(create: fn(cause: E) -> T) -> T:
    fn map[U](transform: fn(value: T) -> U) -> Result[U, E]:
    fn and_then[U](transform: fn(value: T) -> Result[U, E]) -> Result[U, E]:
    fn to_optional() -> Optional[T]:

Result.error#

An expected failure value; it is distinct from faults and cancellation.

Manuscript
case error(cause: E)

Result.ok#

A successful result, retaining its payload without a deep copy.

Manuscript
case ok(value: T)

Result.error.cause#

The original domain error, retained through compatible Result propagation.

Manuscript
cause: E

Result.ok.value#

The successful value returned by unwrap, matching, or propagation.

Manuscript
value: T

Result.and_then[U]#

Calls transform only on success. Its result keeps the same error type.

Manuscript
fn and_then[U](transform: fn(value: T) -> Result[U, E]) -> Result[U, E]:

Result.is_error#

Reports whether this result contains an expected error.

Manuscript
fn is_error() -> Bool:

Result.is_ok#

Reports whether this result contains a successful value.

Manuscript
fn is_ok() -> Bool:

Result.map[U]#

Transforms only a successful payload, preserving an error unchanged.

Manuscript
fn map[U](transform: fn(value: T) -> U) -> Result[U, E]:

Result.to_optional#

Returns some with the original success payload, or none for an error.

Manuscript
fn to_optional() -> Optional[T]:

Result.unwrap#

Returns the successful payload; faults when this is an error.

Manuscript
fn unwrap() -> T:

Result.unwrap_error#

Returns the error payload; faults when this is successful.

Manuscript
fn unwrap_error() -> E:

Result.unwrap_or#

Returns the successful payload, or the eagerly evaluated fallback.

Manuscript
fn unwrap_or(fallback: T) -> T:

Result.unwrap_or_else#

Calls create once with the original error only when this is an error.

Manuscript
fn unwrap_or_else(create: fn(cause: E) -> T) -> T: