artist, "track" => track, "year" => year} 对比 %{artist: a-6ren">
gpt4 book ai didi

elixir - 具有无动于衷的 key 访问的 map

转载 作者:行者123 更新时间:2023-12-04 23:41:19 26 4
gpt4 key购买 nike

在 Map 上匹配定义为原子或字符串的键的最佳实践是什么?

%{"artist" => artist, "track" => track, "year" => year}

对比
%{artist: artist, track: track, year: year}

功能需要在两者上匹配:
def duplicate_post(%{"artist" => artist, "track" => track, "year" => year}) do
...
end

最佳答案

我能想到的最好方法是定义函数两次,每种输入一次,然后从另一个中调用其中一个。

def duplicate_post(%{"artist" => artist, "track" => track, "year" => year}) do
duplicate_post(%{artist: artist, track: track, year: year})
end

def duplicate_post(%{artist: artist, track: track, year: year}) do
...
end

关于elixir - 具有无动于衷的 key 访问的 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36776492/

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