The flatten function in terms of reduce