How To Do A For Loop In Elixir (using only recursion)

Wise words from Programming Elixir by Dave Thomas

L. Peter Deutsch once penned, “To iterate is human, to recurse divine.” And
that’s certainly the way I felt when I first started coding Elixir. The joy of
pattern-matching lists in sets of recursive functions drove my designs. After
a while, I realized that perhaps I was taking this too far.
In reality, most of our day-to-day work is better handled using the various
enumerators built into Elixir. They make your code smaller, easier to understand,
and probably more efficient.
Part of the process of learning to be effective in Elixir is working out for
yourself when to use recursion and when to use enumerators. I recommend
enumerating when you can.

4 Likes