Manuscript Documentation
v0.1.0

@std/optional.ms#

These names are available in the prelude; no import required.

Explicit imports of these prelude declarations are rejected; remove them from the import.

Optional Alternative#

Represents a value that may be absent: some(value) or none.

Manuscript
type Optional[T]:
    case some(value: T)
    case none
    fn is_some() -> Bool:
    fn is_none() -> Bool:
    fn unwrap() -> T:
    fn unwrap_or(fallback: T) -> T:
    fn unwrap_or_else(create: fn() -> T) -> T:
    fn map[U](transform: fn(value: T) -> U) -> Optional[U]:
    fn and_then[U](transform: fn(value: T) -> Optional[U]) -> Optional[U]:
    fn or_else(create: fn() -> Optional[T]) -> Optional[T]:
    fn ok_or[E = MissingValue](cause: Optional[E] = none) -> Result[T, E]:
    fn ok_or_else[E](create: fn() -> E) -> Result[T, E]:

Optional.none#

An absent value with no payload; no T needs to be constructed.

Manuscript
case none

Optional.some#

A present payload, retained by reference when T is mutable.

Manuscript
case some(value: T)

Optional.some.value#

The contained value; unwrap and matching return this original payload.

Manuscript
value: T

Optional.and_then[U]#

Calls transform only when present, returning its Optional unchanged.

Manuscript
fn and_then[U](transform: fn(value: T) -> Optional[U]) -> Optional[U]:

Optional.is_none#

Reports whether this value is absent.

Manuscript
fn is_none() -> Bool:

Optional.is_some#

Returns true for some(value), and false for none.

Manuscript
fn is_some() -> Bool:

Optional.map[U]#

Transforms a present payload; none remains absent.

Manuscript
fn map[U](transform: fn(value: T) -> U) -> Optional[U]:

Optional.ok_or[E]#

Returns ok with the original payload, or error with the eager cause. Without a cause, E is MissingValue and the error names the calling source file and line.

Manuscript
fn ok_or[E = MissingValue](cause: Optional[E] = none) -> Result[T, E]:

Optional.ok_or_else[E]#

Constructs an error once only for none; present payloads remain unchanged.

Manuscript
fn ok_or_else[E](create: fn() -> E) -> Result[T, E]:

Optional.or_else#

Calls create once only when absent, returning its Optional unchanged.

Manuscript
fn or_else(create: fn() -> Optional[T]) -> Optional[T]:

Optional.unwrap#

Returns the payload. Calling this on none raises a fault.

Manuscript
fn unwrap() -> T:

Optional.unwrap_or#

Returns the contained value, or fallback when this is none.

Manuscript
fn unwrap_or(fallback: T) -> T:

Optional.unwrap_or_else#

Computes a fallback only when this is none.

Manuscript
fn unwrap_or_else(create: fn() -> T) -> T: