Adds function flatMapValues.

Thanks @shivaram for comments. I have added tests for this fix.