Search⌘ K
AI Features

Enum: Processing Collections

Explore the Elixir Enum module to master collection processing tasks such as converting, concatenating, mapping, filtering, sorting, splitting, and reducing collections. This lesson helps you understand how to manipulate collections effectively using Enum functions for practical programming.

We'll cover the following...

Introduction

The Enum module is probably the most used of all the Elixir libraries. We can employ it to iterate, filter, combine, split, and otherwise manipulate collections. Here are some common tasks:

  • Convert any collection into a list:
   iex> list = Enum.to_list 1..5
   [1, 2, 3, 4, 5]
  • Concatenate collections:
   iex> Enum.concat([1,2,3], [4,5,6]) 
   [1, 2, 3, 4, 5, 6]
   iex> Enum.concat [1,2,3], 'abc' 
   [1, 2, 3, 97, 98, 99]
  • Create collections whose elements are some function of the original:
   iex> Enum.map(list,
...