I’ve got a list of maps like:
gin = [
%{"key0" => %{a: 0, b: 1, c: 2}},
%{"key1" => %{a: 12, b: 2, c: 1}},
%{"key2" => %{a: 1, b: 3, c: 12}},
[…]
]
and I need to transform it into:
[
{"key0", 2},
{"key1", 1},
{"key2", 12},
[…]
]
I’ve come up with something like:
Enum.map(gin, &{Enum.at(Map.keys(&1), 0), &1[Enum.at(Map.keys(&1), 0)].c})
which does the job but I have that old gut feeling that it could be done more “proper elixir”-ish. Especially not too proud of those Enum.at
s. Any obviously better ways up your experts’ sleeves?