Keyword.new

You're seeing just the function new, go back to Keyword module for more information.

Specs

new() :: []

Returns an empty keyword list, i.e. an empty list.

Examples

iex> Keyword.new()
[]

Specs

new(Enum.t()) :: t()

Creates a keyword list from an enumerable.

Duplicated entries are removed, the latest one prevails. Unlike Enum.into(enumerable, []), Keyword.new(enumerable) guarantees the keys are unique.

Examples

iex> Keyword.new([{:b, 1}, {:a, 2}])
[b: 1, a: 2]

iex> Keyword.new([{:a, 1}, {:a, 2}, {:a, 3}])
[a: 3]

Specs

new(Enum.t(), (term() -> {key(), value()})) :: t()

Creates a keyword list from an enumerable via the transformation function.

Duplicated entries are removed, the latest one prevails. Unlike Enum.into(enumerable, [], fun), Keyword.new(enumerable, fun) guarantees the keys are unique.

Examples

iex> Keyword.new([:a, :b], fn x -> {x, x} end)
[a: :a, b: :b]