map(..).filter_map(..)
chain RS-W1204Using .filter_map(..)
with the identity closure after .map(<f>)
is equivalent
to just .filter_map(<f>)
, which is both more readable and generally more performant.
Consider using .filter_map(<f>)
over .map(<f>).filter_map(|x| x)
.
let a = ["1", "two", "NaN", "four", "5"];
a.iter()
.map(|s| s.parse().ok())
.filter_map(|x| x);
let a = ["1", "two", "NaN", "four", "5"];
a.iter().filter_map(|s| s.parse().ok());