elixir typespecs中的参数化可枚举类型

elixir typespecs中的参数化可枚举类型,types,elixir,Types,Elixir,是否可以参数化elixir中的Enumerable.t类型 因此,目前我有一个函数,它接受foos的列表: @spec the_awesome([foo]) :: any def the awesome(foos) do Enum.reduce(foos, &(bar(&2, &1))) end 实际上,它不必是一个列表!由于唯一的函数调用来自Enum模块,因此我想更改typespec以获取任何可枚举项,但保留可枚举项必须完全由foos组成的要求 差不多 @spec

是否可以参数化elixir中的
Enumerable.t
类型

因此,目前我有一个函数,它接受
foo
s的列表:

@spec the_awesome([foo]) :: any
def the awesome(foos) do
  Enum.reduce(foos, &(bar(&2, &1)))
end
实际上,它不必是一个列表!由于唯一的函数调用来自
Enum
模块,因此我想更改typespec以获取任何可枚举项,但保留可枚举项必须完全由
foo
s组成的要求

差不多

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

这可能吗?

不幸的是,现在不行。我们需要教透析器如何处理协议,如果我们真的想让它们有表现力,并且没有这样做的计划