Working With Data Structures
Earlier we outlined and worked with several different types of data structures. Let's take a closer look at some of these methods.
-
Working With Data StructuresEnum & Map
We've learned about how to create and work with list and map literals in very basic ways. Let's take a look into some of the tooling that Elixir provides as core language features, for working with these data structures.
-
Working With Data StructuresEXERCISE: Map, Filter, Reduce
We have a program that starts with a list of objects read from a file. Using the built-in functions available in the
Enum
andMap
modules, filter out "inactive" items (objects where the "active" attribute is nottrue
), and then log a list of object names to the console. -
Working With Data StructuresTaming List Enumeration with Comprehensions
Often we find ourselves looping over something enumerable; mapping values into another list; and potentially filtering out some unwanted items. Comprehensions use a generator and a filter to provide some excellent syntactic sugar for this kind of task.
-
Working With Data StructuresEXERCISE: Comprehensions
Take another pass at the previous exercise, and use a comprehension to devise a concise solution.
-
Working With Data StructuresLazy Operations with Streams
Elixir's
Stream
module offers some of the same capabilities that we enjoy in theEnum
module, but when working with Streams, computations are performed lazily. This is particularly useful for dealing with huge (or infinitely huge) collections. -
Working With Data StructuresEXERCISE: Skimming a good book
Given the entire text of the book ~Gulliver's Travels~, find the highest- Scrabble-scoring word within the first 1000 lines.
-
Working With Data StructuresRecap & Wrap Up
We'll round out the course by recapping everything we've learned, and finish with some tips for next steps in your mission to become an ace Elixir developer!