我有。。。
%{
"errors" => %{
"abc" => ["example", "something"],
"xyz" => ["thing goes here"]
}
}
我想要。。。
["example", "something", "thing goes here"]
去那里最干净的方法是什么?
如果您不需要错误键优先的顺序保证,您可以将Map.values/1
与List.flatten/1
结合起来,或者使用理解来非常容易地完成
map = %{
"errors" => %{
"abc" => ["example", "something"],
"xyz" => ["thing goes here"]
}
}
map["errors"]
|> Map.values()
|> List.flatten()
#=> ["example", "something", "thing goes here"]
for {_key, items} <- map["errors"], item <- items, do: item
#=> ["example", "something", "thing goes here"]