what is the Erlang any() in Elixir ?
Also any()
, but many people also use term()
.
That means I can translate this Erlang code to Elixir:
{stop, any(), State}
to:
{:stop, any(), state}
I tried but not work.
Can you give us the whole context, speak all the relevant lines in your application?
As it stands there is too little information to help you.
-spec init(Hostname :: inet:hostname(), SessionCount :: non_neg_integer(),
Address :: inet:ip_address(), Options :: list()) -> {'ok', iodata(), #state{}} | {'stop', any(), iodata()}.
This is an example
The syntax for typespecs differ between erlang and elixir. Your erlang typespec:
-spec init(Hostname :: inet:hostname(), SessionCount :: non_neg_integer(),
Address :: inet:ip_address(), Options :: list()) -> {'ok', iodata(), #state{}}
Could look like this in elixir (assuming you use a struct with a typespec for state
instead of an erlang record):
@spec init(hostname :: :inet.hostname(), session_count :: non_neg_integer(),
address :: :inet.ip_address(), options :: list()) :: {:ok, iodata(), State.t()}
That’s a spec, you can translate it to the following Elixir code:
@spec init(hostname :: :inet.hostname, session_count :: non_neg_integer(), address :: :inet.ip_address, options :: list) :: {:ok, iodata, Record.record(state)} | {:stop, any, iodata}
So what exactly do you mean by using “any()” doesn’t work?
Please forgot my stupid question. I mixed the type with value.
After reading doc, looks like any term can be erlang any().
That is why it is called any()