diff options
author | Fernando Tapia Rico <fertapric@gmail.com> | 2021-12-12 20:47:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-12 20:47:48 +0100 |
commit | 4b9bb349e2992dfa62e1575045157dbdaf782719 (patch) | |
tree | 7eb0aaa8166becd4ccf94d2280664579e04f7a57 | |
parent | 9c600bbef7f4d31b7e19e3bf85910008c7d97464 (diff) | |
download | elixir-4b9bb349e2992dfa62e1575045157dbdaf782719.tar.gz |
Improve Keyword docs and examples (#11476)
-rw-r--r-- | lib/elixir/lib/keyword.ex | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/elixir/lib/keyword.ex b/lib/elixir/lib/keyword.ex index a5238ef6c..40332069b 100644 --- a/lib/elixir/lib/keyword.ex +++ b/lib/elixir/lib/keyword.ex @@ -92,6 +92,7 @@ defmodule Keyword do iex> %{1 => 2, foo: :bar} %{1 => 2, :foo => :bar} + """ @compile :inline_list_funcs @@ -238,6 +239,7 @@ defmodule Keyword do iex> Keyword.validate([three: 3, four: 4], [one: 1, two: 2]) {:error, [:four, :three]} + """ @doc since: "1.13.0" @spec validate(keyword(), values :: [atom() | {atom(), term()}]) :: @@ -316,6 +318,7 @@ defmodule Keyword do iex> Keyword.validate!([three: 3], [one: 1, two: 2]) ** (ArgumentError) unknown keys [:three] in [three: 3], the allowed keys are: [:one, :two] + """ @doc since: "1.13.0" @spec validate!(keyword(), values :: [atom() | {atom(), term()}]) :: keyword() @@ -877,11 +880,14 @@ defmodule Keyword do ## Examples - iex> Keyword.replace_lazy([{:a, 1}, {:b, 2}], :a, fn v -> v * 4 end) - [{:a, 4}, {:b, 2}] + iex> Keyword.replace_lazy([a: 1, b: 2], :a, fn v -> v * 4 end) + [a: 4, b: 2] + + iex> Keyword.replace_lazy([a: 2, b: 2, a: 1], :a, fn v -> v * 4 end) + [a: 8, b: 2] - iex> Keyword.replace_lazy([{:a, 1}, {:b, 2}], :c, fn v -> v * 4 end) - [{:a, 1}, {:b, 2}] + iex> Keyword.replace_lazy([a: 1, b: 2], :c, fn v -> v * 4 end) + [a: 1, b: 2] """ @doc since: "1.14.0" |