Whenever I think about why I don't like a certain way a language does something, I realize it always goes back to my love for Python. That language has ruined me. haha
No, because overloading is have same parameters with different types, but in patter matching you can have the same type and number of parameters but differs in the content. For example, here!
That's why we never have
switch
in Python 😁And, the dictionary is always a better and cleaner alternative for the ugly switch.
Whenever I think about why I don't like a certain way a language does something, I realize it always goes back to my love for Python. That language has ruined me. haha
❤ for the utmost ruining lang.
Really love this pattern. I have seen various approaches to the
default
case that vary across languages.How would you handle a
default
case in this?My though is to add
|| defaultValue
at the end since a failure to match any property will returnundefined
. Thoughts?That would be handy using a try except:
I added the extra
default
variable just to make the code self explanatory.EDIT: Bad solution, look at the other comments.
You can also use defaultdict in the standard library :D
This is clean :D
This is the answer to this entire thread.
@rhymes and @pedromendes96 got it better than me 😁
Elixir :)
Pattern matching to the rescue ?
Isn't this feature called method overloading ? 🤔
No, because overloading is have same parameters with different types, but in patter matching you can have the same type and number of parameters but differs in the content. For example, here!
I quite like cond as well for certain situations as well.