Search⌘ K
AI Features

Lists

Explore the fundamentals of Elixir lists and how pattern matching works to assign and verify values. Learn to use special variables like the wildcard and the pin operator to control matching behavior. This lesson helps you grasp core list operations essential for functional programming in Elixir.

Elixir lists can be created using square brackets containing a comma-separated set of values. It performs pattern matching. A pattern (the left side) is matched if each term in the pattern can be matched to the corresponding term in the values. A literal value in the pattern matches that exact value, and a variable in the pattern matches by taking on the corresponding value. See the below example.

Here, we have an Odd_num list containing [1, 3, 5] values. When we match it with the [x, y, 7] list, it gives us an error. But it correctly matches the [x, y, 5] list because every value of the Odd_num ...