This can be done more simply using the retain
method:
items.retain(|f| !f.is_nan())
This should also be faster, with one less allocation, but I haven't done any benchmark to confirm that.
When you need to do that with a iterator, I think than using .cloned
and .filter
instead of .filter_map
makes your intention more clear, but this is pretty subjective:
items = items.iter().cloned().filter(|f| !f.is_nan()).collect::<Vec<f64>>();