You could also have multiple function heads for this.
defmodule Foo do
def bar(%{"file" => file}) do
# Do something if the "file" key is found
end
def bar(attrs) do
# Do something if none of the previous function heads match
end
end
Keep in mind you can have more than two function heads.
However, this would mean you will use if / else in your code which is something I actively avoid ever since I learned functional programming. Using case is a very slight (if any) improvement over it but nowadays I’d go for @Ankhers’s approach, every time.