Logo

Programming-Idioms

History of Idiom 189 > diff from v26 to v27

Edit summary for version 27 by CeaselessBanana:
New Rust implementation by user [CeaselessBanana]

Version 26

2020-01-06, 14:51:05

Version 27

2020-03-17, 12:59:28

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements e of list x that match the predicate P.

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements e of list x that match the predicate P.

Extra Keywords
map apply satisfy
Extra Keywords
map apply satisfy
Code
let y = x.iter()
	.filter_map(|v| if P(v) {Some(T(v))} else {None})
	.collect::<Vec<_>>();
Doc URL
https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.filter_map