Types, Operators & Control Flow
Our journey starts with basic types and procedural logic. Even if you're experienced in a wide range of programming languages, there's going to be a lot of stuff -- even at this basic level -- that may change the way you look at writing code forever.
Types, Operators & Control FlowMath & Strings
There's no getting away from these kinds of things. Eventually you're going to need to work with numbers and text, so we'll start with a crash course in some core APIs (including a dip in the Erlang pool) that will make life easy.
There's a lot of capability here, but we'll stay close to the commonly-useful and pragmatic path.
Types, Operators & Control FlowEXERCISE: Projectile Motion
We'll create a simple program that calculates an object's projectile motion, given a launch angle and initial velocity.
Types, Operators & Control FlowEXERCISE: String Acrobatics
We've got a bunch of functions that do various things to string values, but our tests are failing. Let's fix that!
Types, Operators & Control FlowLunch
Break for Lunch
Types, Operators & Control FlowFunctions
It stands to reason that functions are really important in a functional programming language. We'll build and work with named and anonymous functions, combine functions together to form pipelines, and even map out some higher-order functions of our own.
Types, Operators & Control FlowTuples & Lists
Often times we find ourselves needing to work with several objects in a "collection", and will need to choose between Elixir's List and Tuple types. We'll compare and contrast tuples and lists, and write a few programs highlighting the benefits of each.
Types, Operators & Control FlowEXERCISE: Fibonacci Pyramid
Using our knowledge of functions and recursion in Elixir, let's build a function that writes a Fibonacci pyramid to the console.
20 levels deep!
Types, Operators & Control FlowAssociative Data Structures
We have two main associative data structures in Elixir: keyword lists and maps. Let's learn more about them!
Types, Operators & Control FlowEXERCISE: Building up a List
Assembling a bunch of items in a list is really fast, as long as we do it in a way that doesn't involve moving existing items around in memory. We'll write two programs, one which assembles a bunch of dictionary words into a tuple, and another that uses a list instead.
Types, Operators & Control FlowPattern Matching & Guards
This modern language feature allows destructed assignment, and is often used to define several variants of a function, each to handle a specific scenario. This application of pattern matching reduces what would otherwise be a lot of internal function complexity by huge amounts.
Types, Operators & Control FlowEXERCISE: Function Refactoring
We've got an Elixir module that involves some code that could benefit from some pattern matching magic. Refactor the monolith function so all use of if/else are replaced by creating new functions oriented toward handling that specific pattern of arguments.
Types, Operators & Control FlowEXERCISE: A world without if/else
You'll be given an Elixir module that's currently a little messy and confusing. Untangle it by replacing all of the if/else logic with
case.statements and by applying pattern matching in function clauses.
Remember: your goal is to make your code as easy to read and maintain as possible: be clever, but not confusing.
Types, Operators & Control FlowRecap & Wrap Up
We'll go over everything we've covered today, and connect them back to the big picture. This is a great time for Q&A that's broader than the specific topics we've covered so far.