I have a list of rules resembling
rules = {{a -> {1, 2, 3}}, {b -> {2, 3, 4}}, {c -> {3, 4, 5}, c -> {4, 5, 6}}}
How can I neatly rearrange this to get a list of rules where they keys only occur once, and all their respective values are joined together? Desired output
{a -> {1, 2, 3}, b -> {2, 3, 4}, c -> {3, 4, 5, 6}}
I have what I think is an inelegant approach:
Flatten[
GatherBy[rules, Keys] /.
{r__Rule} :> Rule[First @ Keys[{r}], Union @@ Values[{r}]]
]
(* {a -> {1, 2, 3}, b -> {2, 3, 4}, c -> {3, 4, 5, 6}} *)
Is there a better way of doing this?