Control Flow with Functions

Programs typically cover a variety of scenarios, and we need to create code to handle each one. In functional programming, pattern matching and functions are the fundamental tools we use to control the program flow. Until now, we’ve used pattern matching with the = operator to make two things match. It’s useful for making sure our program runs in an expected scenario. When the match is not possible, Elixir raises an error and stops the program process. When we use pattern matching with functions, we can do more than just throw errors, and that’s what we’ll discuss in this section.

Let’s create a simple program that, given two numbers, will say which one is greater. If the numbers are equal, we can show either one ...

Get Learn Functional Programming with Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.