I have a class like:

```
#[derive(Clone,PartialEq,Debug)]
pub enum List<T> {
    Nil,
    Cons(T,Box<List<T>>)
}

```

Now suppose the Lists are created like the following:

```
let x = 
            List::Cons(0,
                Box::new(List::Cons(1,
                Box::new(List::Cons(2,
                Box::new(List::Cons(3,
                Box::new(List::Nil))))))));

```

Now I want to create a map function that applies f to each element in the List type but I have a problem because I do not know how to traverse through this data type.

```
pub fn map<T,U,F:Fn(&T)->U>(f:F,l:& List<T>) -> List<U> {
    let mut myList = List::Nil;
    if let List::Nil = l {
        return List::Nil;
    } 
    //Want to apply F to each element of l and than 
    // append it to myList but do not know how.
    return myList;
}

```

So something like:

```
let x = 
            List::Cons(0,
                Box::new(List::Cons(1,
                Box::new(List::Cons(2,
                Box::new(List::Cons(3,
                Box::new(List::Nil))))))));
map(|val| val+1,&x)

```

Should result in

```
List::Cons(1,
                Box::new(List::Cons(2,
                Box::new(List::Cons(3,
                Box::new(List::Cons(4,
                Box::new(List::Nil))))))));

```

Can someone help me solve this?