9

Just started with Elixir book by Dave Thomas.

It talks about two concepts:

Keyword lists

[ name: "Dave", city: "Dallas", likes: "Programming" ]

Maps

states = %{ "AL" => "Alabama", "WI" => "Wisconsin" }

When would you choose one over the other?

Wand Maker
  • 18,476
  • 8
  • 53
  • 87
  • 2
    possible duplicate of [What is the benefit of Keyword Lists?](http://stackoverflow.com/questions/28180366/what-is-the-benefit-of-keyword-lists) – whatyouhide Jun 27 '15 at 18:35
  • Thanks. I read the link. Though I understood the technical difference, I am still bit unclear about when will you use one over the other – Wand Maker Jun 27 '15 at 19:25
  • 4
    Keyword lists, heritage of Erlang, are used for passing around rather static collections of values such as options, function arguments and the like. They are just lists so they do not have the properties you are usually looking for when choosing an associative data structure, such as constant time access. Maps on the other hand are your weapon of choice for storing and processing actual payload data. – Patrick Oscity Jun 27 '15 at 20:34
  • Thanks @patrick-oscity – Wand Maker Jun 28 '15 at 02:19

1 Answers1

11

There is a chapter in the getting started guide with a quick overview: http://elixir-lang.org/getting-started/maps-and-dicts.html

To sum it up, keyword lists are used for options or when you need to preserve user ordering. For storing actual data, use maps.

José Valim
  • 50,409
  • 12
  • 130
  • 115