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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access