Trait frunk_core::hlist::HMappable
[−]
[src]
pub trait HMappable<Mapper, Index> { 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, Here> for HNil type Output = HNil;
impl<'a, F, R, H> HMappable<HCons<F, HNil>, Here> for &'a HCons<H, HNil> where
F: FnOnce(&'a H) -> R, type Output = HCons<R, HNil>;impl<'a, F, R, H> HMappable<F, Here> for &'a HCons<H, HNil> where
F: Fn(&'a H) -> R, type Output = HCons<R, HNil>;impl<F, MapperHeadR, MapperTail, H, Tail, Index> HMappable<HCons<F, MapperTail>, There<Index>> for HCons<H, Tail> where
F: FnOnce(H) -> MapperHeadR,
Tail: HMappable<MapperTail, Index>, type Output = HCons<MapperHeadR, <Tail as HMappable<MapperTail, Index>>::Output>;impl<F, R, H, Tail, Index> HMappable<F, There<Index>> for HCons<H, Tail> where
F: Fn(H) -> R,
Tail: HMappable<F, Index>, type Output = HCons<R, <Tail as HMappable<F, Index>>::Output>;impl<'a, F, MapperHeadR, MapperTail, H, Tail, Index> HMappable<HCons<F, MapperTail>, There<Index>> for &'a HCons<H, Tail> where
F: FnOnce(&'a H) -> MapperHeadR,
&'a Tail: HMappable<MapperTail, Index>, type Output = HCons<MapperHeadR, <&'a Tail as HMappable<MapperTail, Index>>::Output>;impl<'a, F, R, H, Tail, Index> HMappable<F, There<Index>> for &'a HCons<H, Tail> where
F: Fn(&'a H) -> R,
&'a Tail: HMappable<F, Index>, type Output = HCons<R, <&'a Tail as HMappable<F, Index>>::Output>;