Use flat_map {..} instead of map {..}.flatten

flat_map is over 40% faster for small arrays (see benchmarks)

Also added crude implementation of flat_map for v1.8.7