jisaacstone
jisaacstone

Reputation: 4264

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 foos:

@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 foos

Something like

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

is this possible?

Upvotes: 8

Views: 417

Answers (1)

José Valim
José Valim

Reputation: 51339

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.

Upvotes: 4

Related Questions