Created
June 23, 2018 12:31
-
-
Save rust-play/e0572da05d999cfb6eb802d003b33ffa to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
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