From cb44b4bb15c01714dfc2c1a53ae38e14b482a255 Mon Sep 17 00:00:00 2001 From: Kosmas Chatzimichalis Date: Thu, 16 May 2019 20:31:27 +0200 Subject: [PATCH] Initial Map page (#26450) * Initial Map page * Update index.md --- guide/english/elixir/maps/index.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/guide/english/elixir/maps/index.md b/guide/english/elixir/maps/index.md index b172acfd82..1a274ce559 100644 --- a/guide/english/elixir/maps/index.md +++ b/guide/english/elixir/maps/index.md @@ -3,11 +3,30 @@ title: Maps --- ## Maps -This is a stub. Help our community expand it. +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: -This quick style guide will help ensure your pull request gets accepted. +``` +iex(1)> %{} +%{} +iex(2)> %{1 => "one", 2 => "two", 3 => "three"} +%{1 => "one", 2 => "two", 3 => "three"} - +``` + +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: - +[HexDocs](https://hexdocs.pm/elixir/Map.html)