Enum.into passing a non-empty list is deprecated

The docs say passing a non-empty list as the collectable is deprecated

https://hexdocs.pm/elixir/1.13.2/Enum.html#into/2

This is a common pattern in test fixtures:

Enum.into([a: 1, b: 2], %{b: 3})

which basically takes attrs and overwrites “defaults” in the map

The docs say consider using Keyword.merge(collectable, Enum.to_list(enumerable))

But how do I correctly merge list into a map like above? Because Keyword.merge/2 seems to merge only list into list, and Map.merge/2 only map into map. And I don’t think I should be converting list to a map before the merge.

Any hints, please?

The collectable is the second parameter, which should no longer be a non empty list. The first parameter can be any list.

the collectable is the second argument, not the first one. So you are good there.

1 Like

It’s into(enumerable, collectable)

So my collectable is the map %{b: 3} - so it’s a “non-empy map” rather than “non-empty list” and therefore the deprecation warning doesn’t apply?

Exactly.

1 Like

If you are not getting a warning, and your Elixir version is updated, it is because you are not doing anything wrong.

1 Like