parameterized enumerable type in elixir typespecs

Is it possible to parametrize the Enumerable.t type in elixir?

so currently I have a function that takes a list of foo s:

@spec the_awesome([foo]) :: any
def the awesome(foos) do
  Enum.reduce(foos, &(bar(&2, &1)))
end

and really it does not have to be a list! since the only function call is from the Enum module I'd like to change the typespec to take any Enumerable, but keep the requirement that the Enumerable must consist entirely of foo s

Something like

@spec the_awesome(Enumerable.t(foo)) :: any

is this possible?


Unfortunately not right now. We would need to teach dialyzer how to handle protocols if we really want them to be expressive and there are no plans for doing such.

链接地址: http://www.djcxy.com/p/84006.html

上一篇: 如何将IPA文件上传到新的testflight?

下一篇: elixir typespecs中的参数化可枚举类型