Module: core.option

Source: ./core/option.reef


Overview

core.option - Generic optional value type for safe null handling

Option[T] represents a value that may or may not be present. Use Option instead of null pointers for type-safe absence handling.

This module provides a fully generic Option[T] type that works with any type. Type arguments are inferred automatically in most cases.

Usage: // Constructor inference - no type annotation needed! let some_val = Option_Some(42) // Inferred as Option[int] let none_val = @Option[int].None() // Explicit when no value to infer from

// Function inference - type args inferred from arguments! if is_some(some_val) let value = unwrap_or(some_val, 0) // No [:int] needed end if


Types

Option (enum)

Generic optional type - either Some(value) or None

Variants:

  • Some(T)
  • None

Functions

fn is_some(opt: Option[T]): bool

Returns true if the option contains a value

fn is_none(opt: Option[T]): bool

Returns true if the option is None (no value)

fn unwrap(opt: Option[T]): T

Extracts the value from Some, panics on None SAFETY: Only call on Some values - check with is_some first, or use unwrap_or for a safe default instead.

fn unwrap_or(opt: Option[T], default: T): T

Returns the contained value or a default


Generated by reefc doc