3 ms·
You can actually use the power of generics to get rid of the two inner calls to `into_iter()`: let mut output: Vec<_> = foo.stuff.into_iter()
by saghm 6y ago
You can actually use the power of generics to get rid of the two inner calls to `into_iter()`:
let mut output: Vec<_> =
foo.stuff.into_iter()
.flat_map(|v| v)
.chain(bar.stuff)
.collect();
- coolreader18 6y agoI believe you can just use `.flatten()` instead of `.flat_map(|v| v)`: let mut output: Vec<_> = foo.stuff.into_iter() .flatten() .chain(bar.stuff) .collect(); I might make it slightly more clear what the intent is by doing this: let mut output: Vec<_> = Iterator::chain(foo.stuff.into_iter().flatten(), bar.stuff) .collect(); But still basically the same.