Logo

Programming-Idioms

History of Idiom 189 > diff from v27 to v28

Edit summary for version 28 by programming-idioms.org:
[Rust] Element name e.

Version 27

2020-03-17, 12:59:28

Version 28

2020-03-18, 10:44:21

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<_>>();
Code
let y = x.iter()
	.filter_map(|e| if P(e) {Some(T(e))} else {None})
	.collect::<Vec<_>>();
Doc URL
https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.filter_map
Doc URL
https://doc.rust-lang.org/nightly/std/iter/trait.Iterator.html#method.filter_map