Looping through an array / list

Essential Elixir : part 4 of 10 published on Aug 10, 2015

We have an array/list of posts.

posts = ["Elixir is cool", "Making sense of Ember Data", "Gulp is awesome"]

Our objective is to output each post to console.


We can use Enum.each like this:

Enum.each posts, fn post -> 
  IO.inspect post

Recursion & Pattern Matching

We can also use recursion and pattern matching.

def output_post([post|posts]) do
  IO.inspect post
def output_post([]), do: nil
Next: Viewing all the functions in a module