How can i delete an item from a map of three arguments.
%{
[:a, ["a1", "a2"]] => 1,
[:b, ["b1"]] => 2,
[:c, ["c1", "c2", "c3"]] => 1
}
How can I delete an item from this map? Let’s say I want to delete the key :a
I have tried using Map.drop
and Map.delete
but it doesn’t work on this example.
Thanks
Both of them expect the complete key, not just a part of it. :a
is not a key in your map, it’s just an atom, which happens to be included in one of the keys of your map.
filter_atom = :a
%{
[:a, ["a1", "a2"]] => 1,
[:b, ["b1"]] => 2,
[:c, ["c1", "c2", "c3"]] => 1
}
|> Enum.filter(fn
{[^filter_atom, _], _v} -> false
_ -> true
end)
|> Map.new()
3 Likes
It’s really helpful, may I know whats this operator for ^filter_item
. What’s the role of ^
? what is it called in Elixir?