0.2.0 Preview 1 · Frozen documentation
ResultState
Observes the success tag without copying either payload.
Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. 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.
IsSuccess
pub fn IsSuccess<T, E>(Value: readonly Result<T, E>&) -> boolObserves the success tag without copying either payload. T: Success payload, including void. E: Error payload. Value: Readonly wrapper borrowed only during observation. Return: True for Ok, false for Err; no allocation or callback.
Example
module example.result_composition;
from std.prelude import Result, IsSuccess, IsError, ResultValue, ResultError,
MapResult, MapError, ThenResult, MapOptional, ThenOptional, ValueOr;
fn Twice(Value: i32) -> i32 { return Value * 2; }
fn Describe(Error: i32) -> str { return "failed"; }
fn Checked(Value: i32) -> Result<i32, i32> {
if Value < 0 { return .Err { Error = 7 }; }
return .Ok { Value = Value + 1 };
}
fn Present(Value: i32) -> i32? { if Value == 0 { return none; } return Value; }
fn Main() -> i32 {
var Input: Result<i32, i32> = .Ok { Value = 20 };
if !IsSuccess(Input) || IsError(Input) { return 1; }
ResultValue(Input).Unwrap() += 1;
let Readonly: readonly Result<i32, i32>& = Input;
if ResultValue(Readonly).Unwrap() != 21 { return 2; }
var Mapped = MapResult<i32, i32, i32>(move(Input), Twice);
var Chained = ThenResult<i32, i32, i32>(move(Mapped), Checked);
if ValueOr(move(Chained), 0) != 43 { return 3; }
var Failure: Result<i32, i32> = .Err { Error = 7 };
ResultError(Failure).Unwrap() = 8;
var Described = MapError<i32, i32, str>(move(Failure), Describe);
if ResultError(Described).Unwrap() != "failed" { return 4; }
var Optional: i32? = 21;
var TwiceOptional = MapOptional<i32, i32>(move(Optional), Twice);
var Selected = ThenOptional<i32, i32>(move(TwiceOptional), Present);
if ValueOr(move(Selected), 0) != 42 { return 5; }
return 0;
}IsError
pub fn IsError<T, E>(Value: readonly Result<T, E>&) -> boolObserves the error tag without copying either payload. T: Success payload, including void. E: Error payload. Value: Readonly wrapper borrowed only during observation. Return: True for Err, false for Ok; no allocation or callback.
Documentation snapshot: October 24, 2026 About versions ↗