"foo", "cat" => "", "name" => "generic","fizz" => "", } 您将如何只获取列表中为空-6ren">
gpt4 book ai didi

dictionary - Elixir获得的值在 map 中不为空

转载 作者:行者123 更新时间:2023-12-02 07:21:31 26 4
gpt4 key购买 nike

给定这样的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com