Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir - Difference between keyword lists and maps

Tags:

elixir

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?

like image 527
Wand Maker Avatar asked Jun 27 '15 17:06

Wand Maker


1 Answers

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.

like image 61
José Valim Avatar answered Oct 20 '22 19:10

José Valim