feat: Add article for Elixir Keyword Lists (#36141)
This commit is contained in:
committed by
Quincy Larson
parent
6078081a3f
commit
9d7ad71964
@ -3,11 +3,22 @@ title: Keyword Lists
|
||||
---
|
||||
## Keyword Lists
|
||||
|
||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/elixir/keyword-lists/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
||||
Keyword Lists are used for storing the key-value pairs as tuples.
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
||||
```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.
|
||||
|
||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||
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.
|
||||
|
||||
#### More Information:
|
||||
<!-- Please add any articles you think might be helpful to read before writing the article -->
|
||||
* [Elixir Documentation](https://elixir-lang.org/getting-started/keywords-and-maps.html#keyword-lists)
|
||||
* [Keyword HexDocs](https://hexdocs.pm/elixir/Keyword.html)
|
||||
|
Reference in New Issue
Block a user