From 6bc207baf2ef8e5700a4372f82d63fcfdbbf6b09 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 21 Jun 2016 23:45:58 -0500 Subject: [PATCH] Fix group_by_keys/1 for Elixir 1.3 Enum.group_by/3 is deprecated now, and it seems to be breaking some tests. This fixes the failing doctest and the other failing test. --- lib/httparrot/general_request_info.ex | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/httparrot/general_request_info.ex b/lib/httparrot/general_request_info.ex index 2dda687..9e147e4 100644 --- a/lib/httparrot/general_request_info.ex +++ b/lib/httparrot/general_request_info.ex @@ -20,15 +20,12 @@ defmodule HTTParrot.GeneralRequestInfo do @spec group_by_keys(list) :: map def group_by_keys([]), do: %{} def group_by_keys(args) do - groups = Enum.group_by(args, %{}, fn {k, _} -> k end) - for {k1, v1} <- groups, into: %{} do - values = Enum.map(v1, fn {_, v2} -> v2 end) - |> Enum.reverse - |> flatten_if_list_of_one - {k1, values} - end + args + |> Enum.map(fn {k, v} -> %{k => v} end) + |> Enum.reduce(fn m, acc -> + Map.merge(m, acc, fn _k, v1, v2 -> + [v2, v1] + end) + end) end - - defp flatten_if_list_of_one([h]), do: h - defp flatten_if_list_of_one(list), do: list end