Playing With Fire

Exploring the web one Elixir at a time

Dealing with collections - Enum (and Stream)

The Enum module is one of the main workhorses in your Elixir armoury. This module collects together all the various functions that operate on list (or recursive) structures, or rather Enumerables. If you need a refresher on lists then read the post found here. There is also pretty good information available on the Elixir website - Enumerables and Streams.

The Enum module provides a large amount of functionality which allows us to map, filter, fold, transform and sort any given enumerable - more than we will have space to cover, so we will the most important.


Control your flow

There are several ways in Elixir to control which path through your application is followed based on the data that is provided or the structure/type of the data structure that is being used.

Firstly, we will start with a recap on pattern-matching, then progressing on to guards and then cover the conditional expressions: case, cond and if/else.



eWebmachine 2 - Hello World

Ewebmachine 2 has now been out a little while. This version is a complete rewrite of the project that breaks backward compatibility. Ewebmachine 1 was a wrapper around basho webmachine, whereas Ewebmachine is now a full re-implementation using a new DSL and Plugs.

Because it is different, I thought that I would create a simple HelloWorld just to explore the changes…


The Capture Operator

The capture operator works a little bit like capture groups in regular expressions, but for function arguments. Use of this allows for shortcutting and making more readable short anonymous functions.


Strings in Elixir

Common features

As is common in programming, Elixir has two string formats: single-quoted and double-quoted. These two representations have many things in common:

  • UTF-8 character encoding
  • they can contain escape sequences
  • they allow string interpolation
  • they have a heredoc representation


[ ] or Lists

Of all the data structures that you might use in Elixir, the one that you will undoubtly use the most is the list.

In Elixir a list is a what is commonly referred to in other languages as a linked-list and is used to contain a collection of items of all the same type.


Elixir Types

Elixir has many of the types that you would expect from a modern programming language. The following list details these:

  • integers
  • floating-point numbers
  • atoms
  • ranges
  • regular expressions
  • PIDS (process ids)
  • ports
  • tuples
  • lists
  • keyword lists
  • maps
  • binaries
  • structs


What is this Elixir anyway?

I thought that I should spend some time looking at the basics of Elixir. I will try very hard not to rehash the material that is already out there, but some crossovers might happen.