Elixir Language Data Structures

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • [head | tail] = [1, 2, 3, true] # one can use pattern matching to break up cons cells. This assigns head to 1 and tail to [2, 3, true]

  • %{d: val} = %{d: 1, e: true} # this assigns val to 1; no variable d is created because the d on the lhs is really just a symbol that is used to create the pattern %{:d => _} (note that hash rocket notation allows one to have non-symbols as keys for maps just like in ruby)

Remarks

As for which data structure to us here are some brief remarks.

If you need an array data structure if you're going to be doing a lot of writing use lists. If instead you are going to be doing a lot of read you should use tuples.

As for maps they are just simply how you do key value stores.



Got any Elixir Language Question?