Does "for" always check the type of the first argument in each function defined in the protocol?
EDIT (rephrasing): When a protocol method has only one argument, the implementation is determined based on the type of that single argument (direct or Any). When a protocol method has several arguments, which one is used to find the appropriate implementation? Is it always the first? Can I change it?
Implementation is always determined based on the first argument.
, . def , , .
def
, , ( t), ( t impl_for!, , ).
t
impl_for!
A defimpl , , defprotocol. , , .
defimpl
defprotocol
, for , . , , , Elixir , . , , Any . , , , .
for
Any
, :
https://github.com/elixir-lang/elixir/blob/150a8a1dcd3610d5ff875e00a1c8779894456ca6/lib/elixir/lib/protocol.ex#L522 https://github.com/elixir-lang/elixir/blob/150a8a1dcd3610d5ff875e00a1c8779894456ca6/lib/elixir/lib/protocol.ex#L456
, - , .
28 .ex, , , : https://github.com/elixir-lang/elixir/blob/150a8a1dcd3610d5ff875e00a1c8779894456ca6/lib/elixir/lib/protocol.ex#L28
, , . .
Source: https://habr.com/ru/post/1569217/More articles:Laravel: organizing tests into folders and running them - unit-testingThe flow around the variable was damaged - cpython3 line "abcd" print: aababcabcd? - pythonWhy can a member function be called temporarily, but a global function cannot? - c ++Return HTML file from JAX-RS service - jax-rsC # 6 safe navigation not working in VS2015 preview - c #Команда git не распознается в окне инструментов терминала в IntelliJ IDEA - gitDisable optimistic global locking in Grails - grailsHow to make a list of tuples with matplotlib? - pythonJava applets and proxies - javaAll Articles