List and Enumeration Basics

Buy or Subscribe

You can access this course in just a minute, and support my efforts to rid the world of crappy online courses!

Buy Standalone  Subscribe

Four Important Friends

There are three Elixir modules that you'll use most often when working with lists of data: Enum, List and Keyword:

  • Enum does enumeration functions. Mapping data, filtering, finding, grouping... things like that. This module is absolutely fundamental; get to know it!
  • List handles list-specific operations whereas Enum will work with anything that you iterate over (or that is enumerable). Inserting, deleting, first and last - the List module is another that you'll want to know well.
  • As you might suspect, Keyword does a lot of what List does, but for keyword lists.

In addition to these, Elixir supports list comprehensions. This is syntactic sugar for iterating over enumerable structures, but comes with built-in filters and the unique ability to have more than one generator. We'll get to these last - they can be quite complicated.