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?
For this purpose Elixir has @spec annotation to describe the specification of a function that will be checked by compiler. However in some cases specification is going to be quite big and complicated. If you would like to reduce complexity, you want to introduce a custom type definition.
TypeSpec provides metadata describing an object accepted or returned by TensorFlow APIs. Concrete subclasses, such as tf. TensorSpec and tf. RaggedTensorSpec , are used to describe different value types.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With