This looks like the default implementation of mapValues.