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

MapOptional

Consumes one wrapper and invokes its safe callback only for the selected case.

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.

MapOptional

pub fn MapOptional<T, U>(mut Value: T?, Mapper: fn(T) -> U) -> U?
    where T: Movable where U: Movable

Consumes one wrapper and invokes its safe callback only for the selected case.

Unselected owned payloads transfer without copying. The callback is invoked exactly once for the selected case and never for the other case; callback captures/costs keep their own contract. This helper adds no allocation, synchronization or implicit error propagation. Reference payloads remain aliases. T: Exact movable payload representation. U: Exact movable payload representation. Value: Owned wrapper consumed by this call; explicitly move noncopy named inputs. Mapper: Nonnullable safe callback with exact input/output types. Return: Transformed selected payload or preserved opposite case.

MapOptional

pub fn MapOptional<T, U, C>(mut Value: T?, mut Mapper: C) -> U?
    where T: Movable where U: Movable where C: UnaryCallable<T, U>, Movable

Consumes one wrapper and invokes its safe callback only for the selected case.

Unselected owned payloads transfer without copying. The callback is invoked exactly once for the selected case and never for the other case; callback captures/costs keep their own contract. This helper adds no allocation, synchronization or implicit error propagation. Reference payloads remain aliases. T: Exact movable payload representation. U: Exact movable payload representation. C: Concrete movable exact safe readonly callback environment. Value: Owned wrapper consumed by this call; explicitly move noncopy named inputs. Mapper: Owned concrete safe callback with exact input/output types. Return: Transformed selected payload or preserved opposite case.

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