How to check if the params has a parameter but it is nil or it is not there at all?

basically the title, I would need to check the params and do different things depending on whether there is a parameter with a value, is that value nil or not, or the parameter is not there at all.
Is this possible?

Thank you

case Map.fetch(params, key) do
  {:ok, nil} -> # it's here and it's nil
  {:ok, value} -> # it's here and it's not nil
  :error -> # it isn't present
end
7 Likes
case params do
  %{"foo" => nil} -> # it is nil
  %{"foo" => val} -> # it is there and has a value
  %{} -> # it is not there
end
5 Likes