Using Recursion in Elixir
rob.conery.io
rob.conery.io
The post still seems to be more about pattern matching than recursion, but at least recursion is in there somewhere!
Let's pretend we can alias these functions using AS
def map_single({:ok, res}) AS fun1
def map_single({:cols_and_first, cols, first_row}) AS fun2
def map_single({:zipped, list}) AS fun3
def map_single({:error, err}) AS fun4
Notice how it's called.fun1 calls fun2
fun2 calls fun3
fun4
to be recursive, a function must call itself or another function that calls it. neither of this is true. What the article is talking about is pattern matching.
This site is another one that requires javascript to see any content for no apparent reason. Worse when scrolling on a narrow window (so that search is not on the right) like on a tablet, when you scroll up it jumps to the top rather than scrolling up so you lose where you are. When you scroll back down it jumps back to where it was so its hard to scroll up reliably.
Also regarding the content, I actually prefer the original code for some reason over the multitude of helper functions. But I guess that is a matter of style.
> I know that there is a ton of room for improvement – so if you have a thought please share.
Sheesh.
But this guy is ostensibly a professional. His CV lists a host of industry experience over the years.
And yet it seems he doesn't understand recursion? That's... Remarkable.
For function overloading the decision for which implementation to use usually happens at compile time along with the type checking. Pattern matching happens at runtime but is more powerful since you can pattern match based on you guessed it: patterns, instead of just types.
Another small difference is that with overloading multiple functions with different signatures are created (they just share name) but with pattern matching there is a single function with multiple "function clauses".