Exnew
Elixir struct wrapper.
iex> {:module, module, _, _} = defmodule Foobar do
...> use Exnew
...> defstruct [:c, :d]
...>
...> @impl true
...> def handle_new(%{c: 1, d: 2}), do: {:ok, %{c: 2, d: 1}}
...> def handle_new(%{c: 3, d: 4}), do: {:ok, %{c: 3, d: 4}}
...> def handle_new(_), do: {:error, :unmatched}
...> end
iex> module.new(%{c: 1, d: 2, e: 3}) |> Map.from_struct()
%{c: 2, d: 1}
iex> module.new([])
** (ArgumentError) [:unmatched] %{}Installation
If available in Hex, the package can be installed
by adding exnew to your list of dependencies in mix.exs:
def deps do
[
{:exnew, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exnew.