Re:The Next Step for Generics
by saghm on Tuesday June 16, 2020 @04:42PM
(#23543823)
You can actually use the power of generics to get rid of the two inner calls to `into_iter()`:
[ Parent
| on HN ]
Re:The Next Step for Generics
by coolreader18 on Tuesday June 16, 2020 @10:42PM
(#23547132)
I 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.