9 ms·
I thought pattern matching in C# would look like pattern matching in Elixir. For example, two functions with different signatures run based on the parameters yo
by sergiotapia 10y ago
I thought pattern matching in C# would look like pattern matching in Elixir. For example, two functions with different signatures run based on the parameters you give it.
def hello("sergio") do
IO.puts "Hello Sergio"
end
def hello(name) do
IO.puts "Hello #{name}"
end
---
hello("sergio") => "Hello Sergio"
hello("mia") => "Hello mia"
- daxfohl 10y agoIsn't that more an example of `multiple dispatch` rather than `pattern matching`?
- sergiotapia 10y agoIn Elixir land it's been taught to me as pattern matching. I have never heard of `multiple dispatch`.
- muhmi 10y agoBoth :) You can pattern match in function head (definition) http://elixir-lang.org/getting-started/pattern-matching.html http://elixir-lang.org/getting-started/pattern-matching.html