From 9d7ad71964d0488983884b00f836db631793baf9 Mon Sep 17 00:00:00 2001 From: Mandar Vaze Date: Sat, 20 Jul 2019 02:44:41 +0530 Subject: [PATCH] feat: Add article for Elixir Keyword Lists (#36141) --- guide/english/elixir/keyword-lists/index.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/guide/english/elixir/keyword-lists/index.md b/guide/english/elixir/keyword-lists/index.md index 2109e2251d..6ce7d47c6d 100644 --- a/guide/english/elixir/keyword-lists/index.md +++ b/guide/english/elixir/keyword-lists/index.md @@ -3,11 +3,22 @@ title: Keyword Lists --- ## Keyword Lists -This is a stub. Help our community expand it. +Keyword Lists are used for storing the key-value pairs as tuples. -This quick style guide will help ensure your pull request gets accepted. +```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. - +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: - + * [Elixir Documentation](https://elixir-lang.org/getting-started/keywords-and-maps.html#keyword-lists) + * [Keyword HexDocs](https://hexdocs.pm/elixir/Keyword.html)