Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created August 13, 2013 08:39
Show Gist options
  • Save mitsuhiko/6219107 to your computer and use it in GitHub Desktop.
Save mitsuhiko/6219107 to your computer and use it in GitHub Desktop.
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