Skip to content

Instantly share code, notes, and snippets.

@brendanzab
Forked from bstrie/map.rs
Last active August 29, 2015 13:58
Show Gist options
  • Save brendanzab/10065372 to your computer and use it in GitHub Desktop.
Save brendanzab/10065372 to your computer and use it in GitHub Desktop.
use std::iter::Iterator;
fn map<T, U, I: Iterator<T>>(fun: |T| -> U, mut iter: I) -> Vec<U> {
let mut acc = vec![];
for elt in iter {
acc.push(fun(elt));
}
acc
}
fn main() {
let x = map(|x| x + 2, vec![1u,2,3].move_iter());
println!("{}", x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment