有没有办法在 Erlang 中创建一流的模式?我需要能够创建模式并将其作为参数传递给其他函数,但我知道模式在 Erlang 中不是一流的。我还查看了 Elixir,但就模式而言,它似乎没有提供更多功能。
我想知道是否有人想出了一个简单的解决方案来解决这个问题。我正在考虑尝试实现这样的东西:
% Instead of using variables, we would just use uppercase atoms which would serve as vars
% A passable pattern
Pattern = {ok, 'Result'}.
% Custom function to check for matches
match(pattern, {ok, [1,2,3]}). % => true
我是 Erlang 的新手,所以也许这完全没有必要。也许有一个图书馆可以做这种事情?
任何意见是极大的赞赏。提前致谢!