Skip to content

Instantly share code, notes, and snippets.

@bstrie
Created April 7, 2014 21:22
Show Gist options
  • Save bstrie/10059739 to your computer and use it in GitHub Desktop.
Save bstrie/10059739 to your computer and use it in GitHub Desktop.
fn map<T, U>(fun: |T|->U, coll: ~[T]) -> ~[U] {
let mut acc = Vec::new();
for elt in coll.move_iter() {
acc.push(fun(elt));
}
acc.move_iter().collect()
}
fn main() {
let x = map(|x| x+2, ~[1u,2,3]);
println!("{:?}", x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment