给定这样的 map :
mapOne = %{"dog" => "foo", "cat" => "", "name" => "generic","fizz" => "", }
您将如何只获取列表中为空的值的键?["cat", "fizz"]
似乎Enum.filter返回的是键,值对的列表,而不仅仅是该列表
mapOne |> Enum.filter(fn {k,v} -> if v == "" do k end end)[{"cat", ""}, {"fizz", ""}]
谢谢!

最佳答案

这种情况下的理解能力很好:

iex(1)> mapOne = %{"dog" => "foo", "cat" => "", "name" => "generic","fizz" => "", }

iex(2)> for {k, v} <- mapOne, v == "", do: k

["cat", "fizz"]

关于dictionary - Elixir获得的值在 map 中不为空,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44579657/

10-10 06:45