In Elixir I can check if a variable is a map or a struct, by calling Kernel.is_map/1 which makes sense because Structs are Maps underneath, but I'd like to differentiate between the two. I know that I can call __struct__ on a Struct to get it's module name but calling it on a normal map throws:
** (KeyError) key :__struct__ not found in: %{}
So my question is, How do I check if a variable is a map or a struct?
Example use case:
# I want to handle struct and map inputs differently in my Module
defmodule DifferentThings do
def do_something(arg) when is_map(arg) do
# Do something with Maps
end
def do_something(arg) when is_struct(arg) do
# But handle Structs differently
# Issue is, `is_struct` does not exist
end
end