在Elixir中,我没有写这样的东西,而是把它简化成:
case getUser(id) do
%User{status: "pending"} -> something()
%User{status: "available"} -> something()
_ -> something_else()
end
我把它简化成:
case getUser(id) do
%User{status: "pending" | "available"} -> something()
_ -> something_else()
end
但是出现了错误
cannot find or invoke local |/2 inside match. Only macros can be invoked in a match and they must be defined before their invocation. Called as: "pending" | "available"
有没有更好的方法?我不想把同一个函数写两次。