Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

ValueOr

Consumes the selected value or an eagerly supplied fallback.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.prelude

import std.prelude;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

ValueOr

pub fn ValueOr<T, E>(mut Value: Result<T, E>, mut Fallback: T) -> T
    where T: Movable where E: Movable

Consumes the selected value or an eagerly supplied fallback.

The unreturned fallback/payload is destroyed normally. No default evaluation is delayed and no allocation, copying or implicit error logging is introduced. T: Movable success/optional payload, including exact reference payloads. E: Movable error discarded on fallback selection. Value: Owned wrapper consumed by this call. Fallback: Owned eager fallback, consumed on absence/error and otherwise destroyed. Return: Owned selected value or Fallback; reference payloads remain aliases.

ValueOr

pub fn ValueOr<T>(mut Value: T?, mut Fallback: T) -> T
    where T: Movable

Consumes the selected value or an eagerly supplied fallback.

The unreturned fallback/payload is destroyed normally. No default evaluation is delayed and no allocation, copying or implicit error logging is introduced. T: Movable success/optional payload, including exact reference payloads. Value: Owned wrapper consumed by this call. Fallback: Owned eager fallback, consumed on absence/error and otherwise destroyed. Return: Owned selected value or Fallback; reference payloads remain aliases.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library