diff --git a/README.md b/README.md index 0a42958..a4cc82a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_773 TILs and counting..._ +_774 TILs and counting..._ --- @@ -118,6 +118,7 @@ _773 TILs and counting..._ ### Elixir +- [All Values For A Key In A Keyword List](elixir/all-values-for-a-key-in-a-keyword-list.md) - [Append To A Keyword List](elixir/append-to-a-keyword-list.md) - [Assert An Exception Is Raised](elixir/assert-an-exception-is-raised.md) - [Binary Representation Of A String](elixir/binary-representation-of-a-string.md) diff --git a/elixir/all-values-for-a-key-in-a-keyword-list.md b/elixir/all-values-for-a-key-in-a-keyword-list.md new file mode 100644 index 0000000..ee79173 --- /dev/null +++ b/elixir/all-values-for-a-key-in-a-keyword-list.md @@ -0,0 +1,22 @@ +# All Values For A Key In A Keyword List + +A keyword list in Elixir can contain the same key multiple times. + +```elixir +kwl = [a: 1, b: 2, a: 3, c: 4] +#=> [a: 1, b: 2, a: 3, c: 4] +``` + +The `get/2` function will only grab the value of the first occurrence. + +```elixir +Keyword.get(kwl, :a) +#=> 1 +``` + +You can use `get_values/2` to retrieve _all_ values associated with the key. + +```elixir +Keyword.get_values(kwl, :a) +#=> [1, 3] +```