Skip to content

std::option

Status: experimental

Data-last Option combinators for pipeline chaining: map, filter, unwrap_or, and_then, etc.

API details and source

The implementation source contains the complete declarations and implementation notes. The table below lists canonical Gossamer call signatures; every item name links directly to its implementation file.

Item Canonical signature or declaration Description
and_then fn and_then<T, U>(f: Fn(T) -> Option<U>, value: Option<T>) -> Option<U> Chains a fallible step: Some(v) -> f(v), None stays None.
filter fn filter<T>(predicate: Fn(T) -> bool, value: Option<T>) -> Option<T> Keeps Some(v) only when the predicate holds.
flatten fn flatten<T>(value: Option<Option<T>>) -> Option<T> Collapses Option> one level.
is_none fn is_none<T>(value: Option<T>) -> bool True for None.
is_some fn is_some<T>(value: Option<T>) -> bool True for Some.
iter fn iter<T>(value: Option<T>) -> Vec<T> Zero-or-one element sequence view.
map fn map<T, U>(f: Fn(T) -> U, value: Option<T>) -> Option<U> Transforms the Some payload, None stays None.
or fn or<T>(fallback: Option<T>, value: Option<T>) -> Option<T> First Some of self and the alternative.
or_else fn or_else<T>(fallback: Fn() -> Option<T>, value: Option<T>) -> Option<T> First Some of self and a lazily built alternative.
unwrap_or fn unwrap_or<T>(fallback: T, value: Option<T>) -> T Unwraps with a fallback value for None.
unwrap_or_else fn unwrap_or_else<T>(fallback: Fn() -> T, value: Option<T>) -> T Unwraps with a lazily computed fallback for None.
zip fn zip<T, U>(other: Option<U>, value: Option<T>) -> Option<(T, U)> Pairs two Somes into Some((a, b)).