[−][src]Struct lhlist::iter::MapAdapter
Function mapping iterator component.
Transforms input using a function implementing MapFunc. Created by calling
the map
method on a ConsIterator or
ValuesIterator.
Example
use lhlist::*; use lhlist::iter::*; // Create the labels new_label![Label1: Vec<usize>]; new_label![Label2: Vec<&'static str>]; new_label![Label3: Vec<f64>]; // Instantiate the list let test_list = lhlist![ Label1 = vec![8usize, 4, 1, 5, 2], Label2 = vec!["Hello", "World!"], Label3 = vec![0.4f64, -3.5, 3.5, 0.3], ]; // Define the mapped function struct CountFn; impl<T> MapFunc<&Vec<T>> for CountFn { type Output = usize; fn call(&mut self, vec: &Vec<T>) -> usize { vec.len() } } // Apply the function and collect into an unlabeled list let counts = test_list.iter_values().map(CountFn).collect_into_hlist(); assert_eq!(counts, cons![5, 2, 4]); // We can also get a labeled version, but first we have to define the target labels new_label![Label1Count: usize]; new_label![Label2Count: usize]; new_label![Label3Count: usize]; let counts = test_list.iter_values().map(CountFn) .collect_into_labeled_hlist::<Labels![Label1Count, Label2Count, Label3Count]>(); assert_eq!(counts, lhlist![Label1Count=5, Label2Count=2, Label3Count=4]);
Trait Implementations
impl<F, T> Adapter<T> for MapAdapter<F> where
F: MapFunc<T>,
[src]
F: MapFunc<T>,
type Output = <F as MapFunc<T>>::Output
Transformation output type
fn adapt(&mut self, input: T) -> Self::Output
[src]
impl<F: Debug> Debug for MapAdapter<F>
[src]
Auto Trait Implementations
impl<F> Send for MapAdapter<F> where
F: Send,
F: Send,
impl<F> Sync for MapAdapter<F> where
F: Sync,
F: Sync,
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self