Logo

Programming-Idioms

History of Idiom 57 > diff from v52 to v53

Edit summary for version 53 by programming-idioms.org:
[Rust] Avoid link shortener if possible

Version 52

2019-11-12, 22:56:03

Version 53

2020-03-20, 17:54:43

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Extra Keywords
satisfy
Extra Keywords
satisfy
Code
let y: Vec<_> = x.iter().filter(p).collect();
Code
let y: Vec<_> = x.iter().filter(p).collect();
Comments bubble
Iterators are very powerful.

This collects into a vector (other collections are possible).
Comments bubble
Iterators are very powerful.

This collects into a vector (other collections are possible).
Demo URL
http://is.gd/sY2SUv
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=ae3984a086da96ad310b4c7ce6ea49a4