When used in a struct module, automatically generates a method to determine whether an object is of that type.
Instead of writing:
assert Enum.all?(people, fn
%Person{} -> true
_ -> false
end)IsType will let you write cleaner code:
defmodule Person do
use IsType
defstruct id: nil, first_name: nil, last_name: nil
end
assert Enum.all?(people, &Person.is_person?/1)or if you don't like the default name, specify your own with an atom.
defmodule Person do
use IsType, function_name: :is_employee
defstruct id: nil, first_name: nil, last_name: nil
end
assert Enum.all?(people, &Person.is_employee/1)
Summary
Functions
Determines whether a provided struct is the specified module type.