Skip to content

Commit d881d89

Browse files
committed
fix matching on every map in Enum.into/2
1 parent 166685c commit d881d89

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/elixir/lib/enum.ex

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -838,15 +838,16 @@ defmodule Enum do
838838
list ++ to_list(collection)
839839
end
840840

841-
def into(collection, %{}) when is_list(collection) do
842-
:maps.from_list(collection)
843-
end
844-
845841
def into(collection, collectable) do
846-
{ initial, fun } = Collectable.into(collectable)
847-
into(collection, initial, fun, fn x, acc ->
848-
fun.(acc, { :cont, x })
849-
end)
842+
case is_list(collection) and is_map(collectable) and (:maps.size(collectable) == 0) do
843+
true ->
844+
:maps.from_list(collection)
845+
false ->
846+
{ initial, fun } = Collectable.into(collectable)
847+
into(collection, initial, fun, fn x, acc ->
848+
fun.(acc, { :cont, x })
849+
end)
850+
end
850851
end
851852

852853
@doc """

0 commit comments

Comments
 (0)