3 ms·
I find it quite readable especially with nested logic. Here is an example: https://github.com/elixir-ecto/ecto/blob/master/lib/ecto/query/builder.ex#L79 https:
by notpublic 3y ago
I find it quite readable especially with nested logic. Here is an example:
https://github.com/elixir-ecto/ecto/blob/master/lib/ecto/query/builder.ex#L79 https://github.com/elixir-ecto/ecto/blob/master/lib/ecto/que...
Edit: Just remembered another use case where function overload is used to override default implementation
defmodule Downloader do
use GenServer
def handle_cast(:start, state) do
...
end
def handle_cast(:stop, state) do
...
end
end
Here, "use GenServer" imports default implementation of various handlers which can be overridden.
https://github.com/elixir-lang/elixir/blob/main/lib/elixir/lib/gen_server.ex#L857C14-L929 https://github.com/elixir-lang/elixir/blob/main/lib/elixir/l...
- lkuty 3y agoIt is the same function with different clauses using pattern matching. It is a powerful way of handling different cases. There is no overload at all. The concept does not exist in the language. And if the arity differs, then they are completely different functions even if the name is the same.