pub trait Traversable: Functor + Foldable {
// Required methods
fn traverse<'a, F: Applicative, A: 'a + Clone, B: 'a + Clone, Func>(
f: Func,
ta: Apply1L1T<'a, Self, A>,
) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, B>>
where Func: Fn(A) -> Apply1L1T<'a, F, B> + 'a,
Apply1L1T<'a, Self, B>: Clone;
fn sequence<'a, F: Applicative, A: 'a + Clone>(
ta: Apply1L1T<'a, Self, Apply1L1T<'a, F, A>>,
) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, A>>
where Apply1L1T<'a, F, A>: Clone,
Apply1L1T<'a, Self, A>: Clone;
}Expand description
A type class for traversable functors.
Traversable functors can be traversed, which accumulates results and effects in some Applicative context.
Required Methods§
Sourcefn traverse<'a, F: Applicative, A: 'a + Clone, B: 'a + Clone, Func>(
f: Func,
ta: Apply1L1T<'a, Self, A>,
) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, B>>
fn traverse<'a, F: Applicative, A: 'a + Clone, B: 'a + Clone, Func>( f: Func, ta: Apply1L1T<'a, Self, A>, ) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, B>>
Map each element of the Traversable structure to a computation, evaluate those computations and combine the results into an Applicative context.
§Type Signature
forall a b f. (Traversable t, Applicative f) => (a -> f b, t a) -> f (t b)
§Parameters
f: The function to apply to each element, returning a value in an applicative context.ta: The traversable structure.
§Returns
The traversable structure wrapped in the applicative context.
§Examples
use fp_library::classes::traversable::Traversable;
use fp_library::brands::OptionBrand;
let x = Some(5);
let y = OptionBrand::traverse::<OptionBrand, _, _, _>(|a| Some(a * 2), x);
assert_eq!(y, Some(Some(10)));Sourcefn sequence<'a, F: Applicative, A: 'a + Clone>(
ta: Apply1L1T<'a, Self, Apply1L1T<'a, F, A>>,
) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, A>>
fn sequence<'a, F: Applicative, A: 'a + Clone>( ta: Apply1L1T<'a, Self, Apply1L1T<'a, F, A>>, ) -> Apply1L1T<'a, F, Apply1L1T<'a, Self, A>>
Evaluate each computation in a Traversable structure and accumulate the results into an Applicative context.
§Type Signature
forall a f. (Traversable t, Applicative f) => (t (f a)) -> f (t a)
§Parameters
ta: The traversable structure containing values in an applicative context.
§Returns
The traversable structure wrapped in the applicative context.
§Examples
use fp_library::classes::traversable::Traversable;
use fp_library::brands::OptionBrand;
let x = Some(Some(5));
let y = OptionBrand::sequence::<OptionBrand, _>(x);
assert_eq!(y, Some(Some(5)));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.