Python list comprehension is really simple:
>>> l = [x for x in range(1, 10) if x % 2 == 0]
>>> [2, 4, 6, 8]
Does Rust have an equivalent syntax like:
let vector = vec![x for x in (1..10) if x % 2 == 0]
// [2, 4, 6, 8]
Python list comprehension is really simple:
>>> l = [x for x in range(1, 10) if x % 2 == 0]
>>> [2, 4, 6, 8]
Does Rust have an equivalent syntax like:
let vector = vec![x for x in (1..10) if x % 2 == 0]
// [2, 4, 6, 8]
Since rust 2018, you can do:
use cute::c;
…
let vector = c![x, for x in 1..10, if x % 2 == 0];
see https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html for why.