Created
April 7, 2014 21:35
-
-
Save bstrie/10062436 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
use std::iter::{Iterator, FromIterator}; | |
fn map<T, IT: Iterator<T>, U, IU: FromIterator<U>>(fun: |T|->U, coll: IT) -> IU { | |
let mut acc = Vec::new(); | |
for elt in coll.move_iter() { // error: type `IT` does not implement any method in scope named `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