Building Single Purpose Functions
Explore how to build single-purpose functions using Elixir to create a modular and data-centric functional core. This lesson guides you through designing simple, decoupled functions, building quiz templates, and composing these functions to track user progress effectively.
We'll cover the following...
As we start to build our quiz, we will focus on two basic concepts. First, we’ll try to make each function take on one single task, however simple. Second, functions should be relatively short… Along the way, we can examine other principles of good design. Decoupling concepts is a foundational concept for any programming, regardless of language.
Building our quiz
Let’s put this advice into practice as we build our quiz. Recall our initial structure for quizzes. We have the following:
-
The struct
-
The constructor
-
The common aliases
We’ll add this to /lib/mastery/core/quiz.ex:
Sometimes, we don’t need to ...