Created
April 7, 2014 21:22
-
-
Save bstrie/10059739 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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