Elixir from the ground up
Unchanged data, small functions, and a pipe that reads left to right
- Beginner
- 12 chapters
- 212 min read
Learn Elixir by writing it: printing and values, atoms and text, the equals sign that matches, tuples and lists, case and guards, named functions in modules, the pipe, Enum and String, maps, structs, recursion with heads and tails, ending with a small sales report that uses all of it.
What You'll Learn
- Print output three ways and paste values into text
- Tell atoms, strings and numbers apart, and use the String tools
- Match values apart with the equals sign, and pin a name to its value
- Choose between a tuple and a list, and walk a list by head and tail
- Choose a path with case, cond and guards, and know what counts as true
- Name work in modules, with default arguments, private helpers and several heads
- Chain steps with the pipe so code reads in the order the steps run
- Ask collections questions with Enum, and tidy text with String
- Store records in maps, and change one without touching the original
- Give data a shape with structs, and match on the shape in a function head
- Write recursion over lists, with an accumulator and a reason to prefer it
- Assemble a small report from maps, a group by, a fold and a formatted output
Prerequisites
- No programming experience needed — this course starts at the first line
- Any other language you know will make the early chapters quick
Course Content
- 01Your first ElixirNot started
What Elixir is, how a program says something, and the values it prints: text, whole numbers and decimal fractions.
- 02Values: numbers, text and atomsNot started
The three values you will use most: whole numbers and decimal fractions, text, and atoms — the little labels that mean themselves.
- 03Pattern matching: the equals sign that matchesNot started
In Elixir the equals sign does not mean "put this in that" — it means "make these two fit". That single idea does the work other languages hand to destructuring, type checks and switches.
- 04Tuples and listsNot started
Two containers, two jobs: a tuple holds a few values that travel together, a list holds any number of values in order. Lists are chains, which is why growing one at the front is cheap.
- 05Decisions: case, cond and guardsNot started
Three ways to choose a path — case on the shape of a value, guards for a condition a pattern cannot express, and cond for a ladder of questions.
- 06Functions in modulesNot started
Naming work: a module groups related functions, a function can have several heads that match different shapes of input, defaults make the common call short, and defp keeps helpers inside.
- 07The pipe: pass this alongNot started
The pipe operator takes the value on its left and hands it to the call on its right as the first argument. It changes nothing about the data — only the order in which you read the steps.
- 08Enum and String: the toolboxNot started
The two modules you will use every day. Enum answers questions about collections — map, filter, reduce, sum, count, sort and group — and String tidies text.
- 09Maps: records with namesNot started
A map holds values under names, which makes it the record of an Elixir program. Maps are values, so changing one gives back a new map and leaves the old one alone.
- 10Structs: maps with a shapeNot started
A struct is a map with a fixed set of fields and a name. The name lets a function head match on the kind of thing it was given, which turns whole branches of code into patterns.
- 11Recursion instead of loopsNot started
A list is a head and a tail, so a function that handles one item and calls itself on the tail handles any list. This is the loop Elixir asks you to write, and it costs no growing pile of work.
- 12Putting it together: a sales reportNot started
A capstone that uses most of the course: records as maps, a module of named work, a group by town, a fold for each group, money formatted to two places, and a report printed in a chosen order.
