[][src]Struct lhlist::iter::MapAdapter

pub struct MapAdapter<F> { /* fields omitted */ }

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]

type Output = <F as MapFunc<T>>::Output

Transformation output type

impl<F: Debug> Debug for MapAdapter<F>[src]

Auto Trait Implementations

impl<F> Send for MapAdapter<F> where
    F: Send

impl<F> Sync for MapAdapter<F> where
    F: Sync

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self