Logo

Programming-Idioms

History of Idiom 247 > diff from v16 to v17

Edit summary for version 17 by cpcloud:
New Rust implementation by user [cpcloud]

Version 16

2021-02-21, 12:56:01

Version 17

2021-03-09, 12:06:17

Idiom #247 Filter list in-place

Remove all the elements from list x that don't satisfy the predicate p, without allocating a new list.
Keep all the elements that do satisfy p.

For languages that don't have mutable lists, refer to idiom #57 instead.

Idiom #247 Filter list in-place

Remove all the elements from list x that don't satisfy the predicate p, without allocating a new list.
Keep all the elements that do satisfy p.

For languages that don't have mutable lists, refer to idiom #57 instead.

Variables
x,p
Variables
x,p
Extra Keywords
keep conserve preserve mutable
Extra Keywords
keep conserve preserve mutable
Code
let mut x: Vec<T>;
x.retain(predicate);
Doc URL
https://doc.rust-lang.org/std/vec/struct.Vec.html#method.retain