Trait frunk_core::hlist::HMappable
[−]
[src]
pub trait HMappable<Mapper> { type Output; fn map(self, folder: Mapper) -> Self::Output; }
Trail that allow for mapping over a data structure using mapping functions stored in another data structure
It might be a good idea to try to re-write these using the foldr variants, but it's a wee-bit more complicated.
Associated Types
type Output
Required Methods
fn map(self, folder: Mapper) -> Self::Output
Maps over the current data structure using functions stored in another data structure.
Examples
let nil = HNil; assert_eq!(nil.map(HNil), HNil); let h = hlist![1, false, 42f32]; // Sadly we need to help the compiler understand the bool type in our mapper let mapped = h.as_ref().map(hlist![ |&n| n + 1, |b: &bool| !b, |&f| f + 1f32]); assert_eq!(mapped, hlist![2, true, 43f32]); // There is also a value-consuming version that passes values to your functions // instead of just references: let mapped2 = h.map(hlist![ |n| n + 3, |b: bool| !b, |f| f + 8959f32]); assert_eq!(mapped2, hlist![4, true, 9001f32]);Run
Implementors
impl<F> HMappable<F> for HNil type Output = HNil;
impl<'a, F, R, H> HMappable<HCons<F, HNil>> for &'a HCons<H, HNil> where
F: FnOnce(&'a H) -> R, type Output = HCons<R, HNil>;impl<F, MapperHeadR, MapperTail, H, Tail> HMappable<HCons<F, MapperTail>> for HCons<H, Tail> where
F: FnOnce(H) -> MapperHeadR,
Tail: HMappable<MapperTail>, type Output = HCons<MapperHeadR, <Tail as HMappable<MapperTail>>::Output>;impl<'a, F, MapperHeadR, MapperTail, H, Tail> HMappable<HCons<F, MapperTail>> for &'a HCons<H, Tail> where
F: FnOnce(&'a H) -> MapperHeadR,
&'a Tail: HMappable<MapperTail>, type Output = HCons<MapperHeadR, <&'a Tail as HMappable<MapperTail>>::Output>;