Optimize flat_map to iterate once instead of twice
Merge pull request #3066 from sferik/flat_map

Optimize flat_map to iterate once instead of twice