Skip to main content

TraverseDispatch

Trait TraverseDispatch 

Source
pub trait TraverseDispatch<'a, FnBrand, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, F: Kind_cdc7cd43dac7585f, FTA, Marker> {
    // Required method
    fn dispatch(
        self,
        ta: FTA,
    ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>>;
}
Expand description

Trait that routes a traverse operation to the appropriate type class method.

The Marker type parameter is an implementation detail resolved by the compiler from the closure’s argument type; callers never specify it directly. The FTA type parameter is inferred from the container argument: owned for Val dispatch, borrowed for Ref dispatch.

§Type Parameters

  • 'a: The lifetime of the values.
  • FnBrand: The brand of the cloneable function to use.
  • Brand: The brand of the traversable structure.
  • A: The type of the elements in the input structure.
  • B: The type of the elements in the output structure.
  • F: The applicative functor brand for the computation.
  • FTA: The container type (owned or borrowed), inferred from the argument.
  • Marker: Dispatch marker type, inferred automatically. Either Val or Ref.

Required Methods§

Source

fn dispatch( self, ta: FTA, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>>

Perform the dispatched traverse operation.

§Type Signature

(self, FTA) -> F (Brand B)

§Parameters
  • self: The closure implementing this dispatch.
  • ta: The structure to traverse.
§Returns

The combined result in the applicative context.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};

let result =
	traverse::<RcFnBrand, OptionBrand, _, _, OptionBrand, _, _>(|x: i32| Some(x * 2), Some(5));
assert_eq!(result, Some(Some(10)));

Implementors§

Source§

impl<'a, 'b, FnBrand, Brand, A, B, F, Func> TraverseDispatch<'a, FnBrand, Brand, A, B, F, &'b <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Ref> for Func
where Brand: RefTraversable, FnBrand: LiftFn + 'a, A: 'a + Clone, B: 'a + Clone, F: Applicative, Func: Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,

Routes Fn(&A) -> F::Of<B> closures to RefTraversable::ref_traverse.

The FnBrand parameter is passed through to the underlying ref_traverse call, allowing callers to choose between RcFnBrand and ArcFnBrand.

The container must be passed by reference (&ta).

§Type Parameters
  • 'a: The lifetime of the values.
  • 'b: The borrow lifetime.
  • FnBrand: The cloneable function brand.
  • Brand: The brand of the traversable structure.
  • A: The type of the elements in the input structure.
  • B: The type of the elements in the output structure.
  • F: The applicative functor brand.
  • Func: The closure type.
Source§

impl<'a, FnBrand, Brand, A, B, F, Func> TraverseDispatch<'a, FnBrand, Brand, A, B, F, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Val> for Func
where Brand: Traversable, A: 'a + Clone, B: 'a + Clone, F: Applicative, Func: Fn(A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,

Routes Fn(A) -> F::Of<B> closures to Traversable::traverse.

The FnBrand parameter is unused by the Val path but is accepted for uniformity with the Ref path.

§Type Parameters
  • 'a: The lifetime of the values.
  • FnBrand: The cloneable function brand (unused by Val path).
  • Brand: The brand of the traversable structure.
  • A: The type of the elements in the input structure.
  • B: The type of the elements in the output structure.
  • F: The applicative functor brand.
  • Func: The closure type.