Initial Map page (#26450)

* Initial Map page

* Update index.md
pull/32163/head^2
Kosmas Chatzimichalis 2019-05-16 20:31:27 +02:00 committed by Paul Gamble
parent ceadc5a839
commit cb44b4bb15
1 changed files with 23 additions and 4 deletions

View File

@ -3,11 +3,30 @@ title: Maps
---
## Maps
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/elixir/maps/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
Maps is the Elixir data structure for key-values.
They are not ordered and allow keys of any type.
Maps are created using the %{} syntax:
<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>.
```
iex(1)> %{}
%{}
iex(2)> %{1 => "one", 2 => "two", 3 => "three"}
%{1 => "one", 2 => "two", 3 => "three"}
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
```
Maps can be accessed with `Map.get/3` or `Map.fetch/2` or with through the `map[]` syntax:
```
iex(1)> map=%{1 => "one", 2 => "two"}
%{1 => "one", 2 => "two"}
iex(2)> Map.fetch(map, 1)
{:ok, "one"}
iex(3)> map[2]
"two"
iex(4)> map[5]
nil
```
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->
[HexDocs](https://hexdocs.pm/elixir/Map.html)