Elixir Language Maps and Keyword Lists Difference between Maps and Keyword Lists


Example

Maps and keyword lists have different application. For instance, a map cannot have two keys with the same value and it's not ordered. Conversely, a Keyword list can be a little bit hard to use in pattern matching in some cases.

Here's a few use cases for maps vs keyword lists.

Use keyword lists when:

  • you need the elements to be ordered
  • you need more than one element with the same key

Use maps when:

  • you want to pattern-match against some keys/values
  • you don't need more than one element with the same key
  • whenever you don't explicitly need a keyword list