The flatMap function in terms of reduce