Type for `|f| move |A| A.map(f)`

It looks like you want a generic function, so define one directly:

#![feature(type_alias_impl_trait)]

fn main() {
    type Mapper<A, B> = impl Fn(Vec<A>) -> Vec<B>;

    //type Map<A, B> = fn(fn(A) -> B) -> Mapper<A, B>;
    //let map: Map::<A, B> = |f| move |a: Vec<A>| a.into_iter().map(f).collect();
    fn map2<A, B>(f: fn(A) -> B) -> Mapper<A, B> {
        move |a| a.into_iter().map(f).collect()
    }

    let f = |a| a * 2;
    let a = vec![1, 2, 3];
    //let b = map(f)(a);
    let b = map2(f)(a);

    // show result
    println!("{:?}", b);
}

Check this.

Leave a Comment