defmodule Test do
def check(opts) do
with {:ok, name} <- check_name(opts),
{:ok, password} <- check_password(opts)
do
{:ok, %{name: name, password: password}}
end
end
defp check_name(%{name: name}), do: {:ok, name}
defp check_name(%{}) , do: {:error, :name_not_found}
defp check_password(%{password: password}), do: {:ok, password}
defp check_password(%{}) , do: {:error, :password_not_found}
end
opts1 = %{name: "Name", password: "secret"}
opts2 = %{name: "Name"}
IO.puts(inspect(Test.check(opts1)))
IO.puts(inspect(Test.check(opts2)))