Working with Enumerable Collections
Discover how to effectively manipulate lists, maps, and other enumerables using Elixir's `Enum` module.
What are Enumerable Collections?
In Elixir, an enumerable is a data structure that you can iterate over, element by element. Think of them as containers for multiple values.
Elixir's powerful Enum module provides many functions to work with these collections efficiently.
- Lists: Ordered collections of any data type.
- Maps: Key-value stores.
- Ranges: Sequences of numbers.
Understanding enumerables is key to functional programming in Elixir.
Working with Elixir Lists
Lists are perhaps the most common enumerable. They are ordered and can hold mixed data types.
Let's see a simple list:
defmodule ListExample do
def run do
my_list = [1, "hello", :atom, 4.5]
IO.puts "My list: #{inspect my_list}"
end
end
ListExample.run()All lessons in this course
- Functions, Modules, and Pipelining
- Working with Enumerable Collections
- Recursion and Higher-Order Functions
- Lazy Evaluation with the Stream Module