mirror of
https://github.com/edgurgel/httparrot
synced 2025-04-05 16:22:32 -04:00
Merge pull request #17 from bratsche/fix-group-by-warning-2
Fix group_by_keys/1 for Elixir 1.3
This commit is contained in:
commit
f15dfcc16f
2 changed files with 10 additions and 13 deletions
|
@ -3,9 +3,9 @@ notifications:
|
||||||
recipients:
|
recipients:
|
||||||
- eduardo@gurgel.me
|
- eduardo@gurgel.me
|
||||||
elixir:
|
elixir:
|
||||||
- 1.0.2
|
- 1.3.0
|
||||||
otp_release:
|
otp_release:
|
||||||
- 17.0
|
- 18.0
|
||||||
- 17.1
|
- 18.1
|
||||||
sudo: false
|
sudo: false
|
||||||
script: mix test --no-start
|
script: mix test --no-start
|
||||||
|
|
|
@ -20,15 +20,12 @@ defmodule HTTParrot.GeneralRequestInfo do
|
||||||
@spec group_by_keys(list) :: map
|
@spec group_by_keys(list) :: map
|
||||||
def group_by_keys([]), do: %{}
|
def group_by_keys([]), do: %{}
|
||||||
def group_by_keys(args) do
|
def group_by_keys(args) do
|
||||||
groups = Enum.group_by(args, %{}, fn {k, _} -> k end)
|
args
|
||||||
for {k1, v1} <- groups, into: %{} do
|
|> Enum.map(fn {k, v} -> %{k => v} end)
|
||||||
values = Enum.map(v1, fn {_, v2} -> v2 end)
|
|> Enum.reduce(fn m, acc ->
|
||||||
|> Enum.reverse
|
Map.merge(m, acc, fn _k, v1, v2 ->
|
||||||
|> flatten_if_list_of_one
|
[v2, v1]
|
||||||
{k1, values}
|
end)
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp flatten_if_list_of_one([h]), do: h
|
|
||||||
defp flatten_if_list_of_one(list), do: list
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue