I have a list of tuples like this:

```
  def pairs do
    person_a = %{name: :a}
    person_b = %{name: :b}
    [{person_a, 1}, {person_b, 5}, {person_a, 2}, {person_b, 6}, {person_a, 3}]
  end

```

And I want to join them based on the name of the person, resulting in this:

```
[{%{name: :a}, [1, 2, 3]}, {%{name: :b}, [5, 6]}]

```

I'm able to accomplish this with the following code:

```
  def group_pairs do
    pairs
    |> Enum.group_by(fn {f, _s} -> f.name end)
    |> Enum.map(fn {k, v} ->
      {elem(List.first(v), 0), Enum.map(v, &elem(&1, 1))}
    end)
  end

```

But this is difficult to read and seems overwrought. I assume there is a cleaner way using some built-in function I don't know about. Is there a better, or more idiomatic, way to accomplish what I'm trying to do?

*Further requirements* 

Note that I want to group by the person's name, not the entire person object. In this toy example, the person object keys are small, but in practice these could be large nested objects, and for the sake of performance I wouldn't want to use those large objects to do comparisons in the group by.