We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
ArgumentError
Keyword.from_keys/2
1 parent a7b2d6c commit 5bf4df5Copy full SHA for 5bf4df5
1 file changed
lib/elixir/lib/keyword.ex
@@ -119,14 +119,23 @@ defmodule Keyword do
119
120
iex> Keyword.from_keys([:foo, :bar, :baz], :atom)
121
[foo: :atom, bar: :atom, baz: :atom]
122
+
123
iex> Keyword.from_keys([], :atom)
124
[]
125
126
+ iex> Keyword.from_keys(["foo"], :bar)
127
+ ** (ArgumentError) expected a list of atoms as keys, got: "foo"
128
"""
129
@doc since: "1.14.0"
130
@spec from_keys([key], value) :: t(value)
131
def from_keys(keys, value) when is_list(keys) do
- :lists.map(&{&1, value}, keys)
132
+ :lists.map(
133
+ fn
134
+ key when is_atom(key) -> {key, value}
135
+ other -> raise ArgumentError, "expected a list of atoms as keys, got: #{inspect(other)}"
136
+ end,
137
+ keys
138
+ )
139
end
140
141
@doc """
0 commit comments