list comprehension w/ iterators in rust

Run Settings
LanguageRust
Language Version
Run Command
/* Rust: Typical rust pattern is .iter().map(...).collect(). .iter() creates an iterator from a iterable data structure .map() creates a new iterator modifying elements .collect() stores all the elements into data structure. Python: list = [i*j for i in range(1, 4) for j in range(2, 5)] print(list */ fn main() { let old_arr = [2, 4, 6]; let new_arr = old_arr.map(|x| 2 * x); println!("old_arr: {:?}", old_arr); println!("new_arr: {:?}", new_arr); }
Editor Settings
Theme
Key bindings
Full width
Lines