Skip to main content

RefTraversable

Trait RefTraversable 

Source
pub trait RefTraversable:
    RefFunctor
    + RefFoldable
    + Kind_cdc7cd43dac7585f {
    // Required method
    fn ref_traverse<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>(
        func: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,
        ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
    ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
       where FnBrand: LiftFn + 'a,
             <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,
             <F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone;
}
Expand description

By-reference traversal of structures.

Similar to Traversable, but the closure receives &A instead of A. This enables traversing collections by reference without consuming elements, or traversing memoized types that only provide &A access.

ref_traverse is the required method.

Required Methods§

Source

fn ref_traverse<'a, FnBrand, A: 'a + Clone, B: 'a + Clone, F: Applicative>( func: impl Fn(&A) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, ta: &<Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <F as Kind_cdc7cd43dac7585f>::Of<'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>>
where FnBrand: LiftFn + 'a, <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone, <F as Kind_cdc7cd43dac7585f>::Of<'a, B>: Clone,

Maps each element by reference to a computation, evaluates them, and combines the results.

§Type Signature

forall A B F. (Applicative F, LiftFn FnBrand) => (&A -> F B, &Self A) -> F (Self B)

§Type Parameters
  • 'a: The lifetime of the elements.
  • FnBrand: The brand of the cloneable function wrapper.
  • 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.
§Parameters
  • func: The function to apply to each element reference.
  • ta: The structure to traverse.
§Returns

The combined result in the applicative context.

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

let v = vec![1, 2, 3];
let result: Option<Vec<String>> =
	ref_traverse::<VecBrand, RcFnBrand, _, _, OptionBrand>(|x: &i32| Some(x.to_string()), &v);
assert_eq!(result, Some(vec!["1".to_string(), "2".to_string(), "3".to_string()]));

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.

Implementors§

Source§

impl RefTraversable for CatListBrand

Source§

impl RefTraversable for IdentityBrand

Source§

impl RefTraversable for OptionBrand

Source§

impl RefTraversable for Tuple1Brand

Source§

impl RefTraversable for VecBrand

Source§

impl<E: Clone + 'static> RefTraversable for ResultErrAppliedBrand<E>

§Type Parameters
  • E: The error type.
Source§

impl<First: Clone + 'static> RefTraversable for PairFirstAppliedBrand<First>

§Type Parameters
  • First: The type of the first value in the pair.
Source§

impl<First: Clone + 'static> RefTraversable for Tuple2FirstAppliedBrand<First>

§Type Parameters
  • First: The type of the first value in the tuple.
Source§

impl<Second: Clone + 'static> RefTraversable for PairSecondAppliedBrand<Second>

§Type Parameters
  • Second: The type of the second value in the pair.
Source§

impl<Second: Clone + 'static> RefTraversable for Tuple2SecondAppliedBrand<Second>

§Type Parameters
  • Second: The type of the second value in the tuple.
Source§

impl<T: Clone + 'static> RefTraversable for ResultOkAppliedBrand<T>

§Type Parameters
  • T: The success type.