Skip to main content

OptionResultExt

Trait OptionResultExt 

Source
pub trait OptionResultExt<T, E> {
    // Required method
    fn sequence(self) -> Result<Option<T>, E>;
}
Expand description

Extends optional results with sequencing.

Required Methods§

Source

fn sequence(self) -> Result<Option<T>, E>

An alias for transpose, a correct name for this function, although written for the fixed data types (Option and Result). See also traverse variant that accepts a mapping closure. Defined by Conor McBride (2005) in Haskell2010 base Data.Traversable.

Traversable structures support element-wise sequencing of Applicative effects (thus also Monad effects) to construct new structures of the same shape as the input.

class (Functor t, Foldable t) => Traversable t where
  sequence :: Applicative f => t (f a) -> f (t a)

From this Haskell definition t is Option and f is Result.

§Examples
use alux_traversable::*;

let r: Result<_, ()> = Some(Ok(42)).sequence();

assert_eq!(r, Ok(Some(42)));

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T, E> OptionResultExt<T, E> for Option<Result<T, E>>

Extends optional results with sequencing.

Source§

fn sequence(self) -> Result<Option<T>, E>

An alias for transpose, a correct name for this function, although written for the fixed data types (Option and Result). See also traverse variant that accepts a mapping closure. Defined by Conor McBride (2005) in Haskell2010 base Data.Traversable.

Traversable structures support element-wise sequencing of Applicative effects (thus also Monad effects) to construct new structures of the same shape as the input.

class (Functor t, Foldable t) => Traversable t where
  sequence :: Applicative f => t (f a) -> f (t a)

From this Haskell definition t is Option and f is Result.

§Examples
use alux_traversable::*;

let r: Result<_, ()> = Some(Ok(42)).sequence();

assert_eq!(r, Ok(Some(42)));

Implementors§