Question: Being new to Elixir I'm having some problems understanding pattern matching.

If I have an Elixir data structure like this:

```
list_with_maps = [%{"id" => 1, "name" => "a"}, %{"id" => 2, "name" => "b"}]

```

What would be the best way to get values of all id fields from it?

Answer: 
You can map over the list and return the id using [Enum.map/2](http://elixir-lang.org/docs/v1.1/elixir/Enum.html#map/2)

```
Enum.map(list_with_maps, fn (x) -> x["id"] end)
[1, 2]

```

You can write the same function using the [capture](http://elixir-lang.org/docs/v1.1/elixir/Kernel.SpecialForms.html#&/1) operator:

```
Enum.map(list_with_maps, & &1["id"])

```

I prefer writing `& &1["id"]` as `&(&1["id"])` but the parentheses are optional.
For sake of completeness for the answers for this question you could also do something like this:

```
defmodule Test do
  def get_all_ids([head | tail ]) do
    IO.puts head["id"]
    get_all_ids(tail)
  end

  def get_all_ids([]) do
    IO.puts "end"
  end
end

```

Which would be used like so:

```
iex(7)> Test.get_all_ids(list_with_maps)
1
2
end
:ok

```

Although I think @Gazler's answer is the better answer in this case.

Oh and since you specifically mentioned pattern matching, this would also work:

```
defmodule Test do
  def get_all_ids([%{"id" => id} = m  | tail ]) do
    IO.puts id
    get_all_ids(tail)
  end

  def get_all_ids([]) do
    IO.puts "end"
  end
end

```

The call would be exactly the same; the difference in the second approach is that it's using a pattern match to parse the map in the argument list. 

You might also change the argument list in this line: `def get_all_ids([%{"id" => id} = m | tail ]) do` to this: `def get_all_ids([%{"id" => id} = _m | tail ]) do` just to avoid the warning about `m` being unused.