2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Keyword Lists
|
|
|
|
---
|
|
|
|
## Keyword Lists
|
|
|
|
|
2019-07-20 02:44:41 +05:30
|
|
|
Keyword Lists are used for storing the key-value pairs as tuples.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-20 02:44:41 +05:30
|
|
|
```shell
|
|
|
|
iex(1)> iex(3)> kw_list = [{:key1, "Val1"}, {:key2, "Val2"}, {:key1, "It is OK to repeat key1"}]
|
|
|
|
[key1: "Val1", key2: "Val2", key1: "It is OK to repeat key1"]
|
|
|
|
```
|
|
|
|
curly braces can be omitted as seen in the `iex` response on the second line.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-20 02:44:41 +05:30
|
|
|
In Keyword Lists, the Keys :
|
|
|
|
|
|
|
|
- Must be atoms
|
|
|
|
- Can be repeated
|
|
|
|
- Are ordered as specified by the developer.
|
|
|
|
|
|
|
|
Keyword lists are default mechanism for passing options to functions in Elixir.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
#### More Information:
|
2019-07-20 02:44:41 +05:30
|
|
|
* [Elixir Documentation](https://elixir-lang.org/getting-started/keywords-and-maps.html#keyword-lists)
|
|
|
|
* [Keyword HexDocs](https://hexdocs.pm/elixir/Keyword.html)
|