The Task

There are many ways in which this story can unfold. Let me choose one that I remember: It all begins with a simple task…

Given a list of groups of people, count how many individuals from a particular country you have.

So, the initial version of a function that solves the problem may look like this:

The important function there is count/2. We added a test/0 function for good measure and if you try and run that function on an Erlang shell you’ll see something like this:

1> c(people).

{ok,people}

2> people:test().

ok

So far so good, but count/2 is deeply nested and some linting tools like Elvis will tell you that you should not write code like that. So, you go ahead and do some refactoring…