Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created June 23, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/e0572da05d999cfb6eb802d003b33ffa to your computer and use it in GitHub Desktop.
Save rust-play/e0572da05d999cfb6eb802d003b33ffa to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
let numbers = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10].into_iter();
let evens = numbers.filter(|x| *x % 2 == 0);
let even_squares = evens.clone().map(|x| x * x);
let result = even_squares.clone().collect::<Vec<_>>();
println!("{:?}", result); // prints [4,16,36,64,100]
println!("{:?}\n{:?}", evens, even_squares);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment