SagaSaga
Standard Library

Std.Maybe

Optional values: a type-safe alternative to null.

Types

Maybe

type Maybe a =
  | Nothing
  | Just a

A value that is either present (Just) or absent (Nothing).

Functions

is_just

fun is_just : Maybe a -> Bool

Returns True if the value is Just.

is_nothing

fun is_nothing : Maybe a -> Bool

Returns True if the value is Nothing.

map

fun map : (f: a -> b) -> (m: Maybe a) -> Maybe b

Applies a function to the inner value if Just, otherwise returns Nothing.

unwrap_or

fun unwrap_or : (default: a) -> (m: Maybe a) -> a

Returns the inner value or a default if Nothing.

unwrap

fun unwrap : (m: Maybe a) -> a where {a: Debug}

Returns the inner value. Panics on Nothing.

and_then

fun and_then : (f: a -> Maybe b) -> (m: Maybe a) -> Maybe b

Chains a function that returns Maybe. Returns Nothing if the input is Nothing.

or_else

fun or_else : (fallback: Maybe a) -> (m: Maybe a) -> Maybe a

Returns the first Just value, or Nothing if both are Nothing.