Module: core.result

Source: ./core/result.reef


Overview

core.result - Result types for error handling

Result types represent operations that can succeed or fail. Use Result instead of returning special error values (like -1 or null).

The canonical type is the generic Result[T, E] (mirrors core.option's Option[T]). Construction requires explicit type args because each variant only carries one of the two type parameters:

let r1: Result[int, string] = @Result[int, string].Ok(42) let r2: Result[int, string] = @Result[int, string].Err("bad input")

Query and unwrap functions infer their type args from the argument:

if is_ok(r1) let v = unwrap_ok(r1) else println(unwrap_err(r1)) end if

unwrap_ok/unwrap_err PANIC when called on the wrong variant — check with is_ok/is_err first, or use unwrap_or for a fallback value. Standard usage pairs E with core.error.Error.


Types

Result (enum)

Variants:

  • Ok(T)
  • Err(E)

Functions

fn is_ok(r: Result[T, E]): bool

Returns true if the result is Ok (success)

fn is_err(r: Result[T, E]): bool

Returns true if the result is Err (failure)

fn unwrap_ok(r: Result[T, E]): T

Extracts the success value from Ok. PANICS if called on Err — check with is_ok first, or use unwrap_or.

fn unwrap_err(r: Result[T, E]): E

Extracts the error value from Err. PANICS if called on Ok — check with is_err first.

fn unwrap_or(r: Result[T, E], default: T): T

Returns the Ok value or a caller-supplied default on Err.


Generated by reefc doc