Skip to content

Instantly share code, notes, and snippets.

@cfr
Forked from mitsuhiko/gist:6219107
Created August 13, 2013 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfr/6220361 to your computer and use it in GitHub Desktop.
Save cfr/6220361 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