ParamMap (ParamMap v0.1.1) View Source
A subset of the Map module that operates on string-keyed maps using
atom key arguments.
Examples
iex> params = %{"color" => "red", "size" => "large", "age" => 100}
iex> ParamMap.get(params, :color)
"red"
iex> ParamMap.delete(params, :size)
%{"color" => "red", "age" => 100}
iex> ParamMap.take(params, [:color, :size])
%{color: "red", size: "large"}
iex> ParamMap.pop(params, :color)
{"red", %{"size" => "large", "age" => 100}}Still works with maps that have atom keys, in case you don't know ahead of time whether the keys are strings or atoms.
iex> params = %{:color => "red", "age" => 100}
iex> ParamMap.get(params, :color)
"red"The params may have a key both as a string and an atom.
get/1, pop/1, and take/2 prioritize the atom key.
delete/2, pop/1 remove both the atom and string version of the key.
iex> params = %{:color => "red", "color" => "blue"}
iex> ParamMap.get(params, :color)
"red"
iex> params = %{:color => "red", "color" => "blue", "age" => 100}
iex> ParamMap.delete(params, :color)
%{"age" => 100}
iex> params = %{:color => "red", "color" => "blue", "age" => 100}
iex> ParamMap.pop(params, :color)
{"red", %{"age" => 100}}