pub fn sequence<'a, Brand: Traversable<'a>, F: Applicative, A: 'a + Clone>(
t: Apply1<Brand, Apply1<F, A>>,
) -> Apply1<F, Apply1<Brand, A>>
Expand description
Evaluate each computation in a Traversable
structure and accumulate the results into an Applicative
context.
Free function version that dispatches to the typeclass’ associated function.
The default implementation of sequence
is implemented in terms of traverse
and identity
where:
sequence = traverse identity
§Type Signature
forall t f a. Traversable t, Applicative f => t (f a) -> f (t a)
§Parameters
t
: ATraversable
structure containingApplicative
computations.
§Returns
An Applicative
containing the accumulated results of the computations.
§Examples
use fp_library::{brands::{VecBrand, OptionBrand}, functions::sequence};
use std::sync::Arc;
assert_eq!(
sequence::<VecBrand, OptionBrand, i32>(vec![Some(1), Some(2), Some(3)]),
Some(vec![1, 2, 3])
);