Functional programming is all about transforming data and if we're going to work with Solar Flares, we need to understand how Lists work - how we query, slice, dice, add and remove. That's what we're going to do now.
There are three Elixir modules that you'll use most often when working with lists of data:
Enumdoes enumeration functions. Mapping data, filtering, finding, grouping… things like that. This module is absolutely fundamental; get to know it!
Listhandles list-specific operations whereas
Enumwill work with anything that you iterate over (or that is enumerable). Inserting, deleting, first and last - the
Listmodule is another that you'll want to know well.
Keyworddoes a lot of what
Listdoes, 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.