I have a function like this:
def get_captain(team_groups) do
flatten_members =
for %{members: members, ratings: ratings} <- team_groups,
# Zipping will create binary tuples from 2 lists
{id, rating} <- Enum.zip(members, ratings),
# Create result value
do: %{member_id: id, rating: rating}
captain =
Enum.sort_by(flatten_members, fn x -> x.rating end, &>=/2)
|> Enum.at(0)
captain.member_id
end
If I change the last line to this:
Enum.sort_by(flatten_members, fn x -> x.rating end, &>=/2)
|> Enum.at(0).member_id
It doesn’t work. captain is a map with member_id as a key. Why doesn’t that work?