How to map and reduce List of Maps in Elixir
问题 What's a good way to map and reduce the elixir's list and convert it into new list. Requirement: 1. Find the maps with same id: 2. Merge the values of "role" key (i.e. Gather all the unique values). 3. For all other maps(elements of list), do nothing. list = [%{"id": 1, "role": ["A", "B"]}, %{"id": 2, "role": ["B", "C"]}, %{"id": 1, "role": ["C", "A"]} ] needs to be converted in the following list: ans_list = [%{"id": 1, "role": ["A", "B", "C"]}, %{"id": 2, "role": ["B", "C"]}] 回答1: You can