pub trait OptionTraversableExt<T> {
// Required methods
fn traverse<F, R, E>(self, f: F) -> Result<Option<R>, E>
where F: FnOnce(T) -> Result<R, E>;
fn traverse_opt<F, R, E>(self, f: F) -> Result<Option<R>, E>
where F: FnOnce(T) -> Result<Option<R>, E>;
}Expand description
Extends optional values with traversal operations.
Required Methods§
Sourcefn traverse<F, R, E>(self, f: F) -> Result<Option<R>, E>
fn traverse<F, R, E>(self, f: F) -> Result<Option<R>, E>
Sequencing operation on Option type when inner type is Applicative or Monad like Result.
See sequence for traverse with identity 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
traverse :: Applicative f => (a -> f b) -> t a -> f (t b)From this Haskell definition t is Option and f is Result.
§Examples
use alux_traversable::*;
let r: Result<_, ()> = Some(42).traverse(|x| Ok(x + 100));
assert_eq!(r, Ok(Some(142)));Sourcefn traverse_opt<F, R, E>(self, f: F) -> Result<Option<R>, E>
fn traverse_opt<F, R, E>(self, f: F) -> Result<Option<R>, E>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T> OptionTraversableExt<T> for Option<T>
Extends optional values with traversal operations.
impl<T> OptionTraversableExt<T> for Option<T>
Extends optional values with traversal operations.
Source§fn traverse<F, R, E>(self, f: F) -> Result<Option<R>, E>
fn traverse<F, R, E>(self, f: F) -> Result<Option<R>, E>
Sequencing operation on Option type when inner type is Applicative or Monad like Result.
See sequence for traverse with identity 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
traverse :: Applicative f => (a -> f b) -> t a -> f (t b)From this Haskell definition t is Option and f is Result.
§Examples
use alux_traversable::*;
let r: Result<_, ()> = Some(42).traverse(|x| Ok(x + 100));
assert_eq!(r, Ok(Some(142)));