Created
August 13, 2013 08:39
-
-
Save mitsuhiko/6219107 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::hashmap::HashMap; | |
fn main() { | |
// create a hashmap | |
let mut hm = HashMap::new(); | |
hm.insert(~"foo", 10); | |
hm.insert(~"bar", 23); | |
hm.insert(~"baz", 99); | |
hm.insert(~"meh", 2); | |
hm.insert(~"muh", -13); | |
hm.insert(~"mop", -23); | |
let x = hm | |
// move all the items out | |
.move_iter() | |
// enumerate them | |
.enumerate() | |
// calculate the square of the values and | |
// flatten the tuple | |
.map(|(i, (k, v))| (i, k, v * v)) | |
// only take the small items | |
.filter(|&(_, _, v)| v.abs() < 1000) | |
// convert into a ~[T] | |
.to_owned_vec(); | |
// debug print it | |
println(x.to_str()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment