Identifying the Data of Our Project
Explore how to build the data layer of an Elixir project by defining templates and questions using maps and structs. Understand how to organize descriptive fields, enable question generation with compiled templates, and validate responses with checker functions to maintain functional immutability in your quiz system.
Creating our core
We’ll create a lib/mastery/core directory to hold the modules with our data layer (and later our core functions).
Defining a template
We’re going to use the primary Elixir data structure, the map. We know that the fields will be a struct. The centerpiece of our quiz is the template. The fields in our templates will serve three purposes—description, question generation, and checking responses.
Description
Our first three fields will describe our templates. As such, we’ll have a name and a category, which we’ll represent as atoms. We’ll also have an instruction to tell users what to do as they answer a question. These are the fields that describe our template:
-
name(atom): The name of this template. -
category(atom): A grouping for questions of the same name. -
instructions...