Adding a function to recursively visit each element of a list and call the group-by and merge functions.