Answers for "rust list comprehension"

0

rust list comprehension

// https://docs.rs/cute/0.3.0/cute/

#[macro_use(c)]
extern crate cute;

let vector = c![x, for x in 1..10, if x % 2 == 0];
Posted by: Guest on February-16-2022
0

rust list comprehension

let v1 = (0u32..9).filter(|x| x % 2 == 0).map(|x| x.pow(2)).collect::<Vec<_>>();
let v2 = (1..10).filter(|x| x % 2 == 0).collect::<Vec<u32>>();

println!("{:?}", v1); // [0, 4, 16, 36, 64]
println!("{:?}", v2); // [2, 4, 6, 8]
Posted by: Guest on February-16-2022

Browse Popular Code Answers by Language