tuple group_by into map
- Dominant language
- Elixir
- Stars
- 36
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Suppose you have data in the form ` [{"M1", "C1"}, {"M1", "C2"}, {"M2", "C3"}]` and you want a map "grouped by":
`[%{c: ["C2", "C1"], m: "M1"}, %{c: ["C3"], m: "M2"}]`
A helper function (perhaps not optimum :)
```elixir
group_assoc = fn list ->
list
|> Enum.map(fn {m, c} -> %{m: m, c: c} end)
# list_maps = [%{m: "M1", c: "C1"}, %{m: "M1", c: "C2"}, %{m: "M2", c: "C3"}]
|> Enum.group_by(& &1.m)
|> Enum.map(fn {k, v} ->
%{m: k, c: Enum.reduce(v, [], fn e, acc -> [e.c | acc] end)}
end)
end
```
Contributor guide
No contributing guide indexed for this repository
Research direction
No file or test is named in the issue, so first inspect the repository's existing Elixir utility modules and test structure to find the appropriate entry point. Compare the requested tuple input and grouped map output with existing conventions; done means an agreed helper is implemented with tests covering the shown M1/M2 example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100