IsType

Hex VersionHex DownloadsLicense

Description

When used in a struct module, IsType 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)

Installation

IsType can be installed by adding is_type to your list of dependencies in mix.exs:

def deps do
[
{:is_type, "~> 0.1.0"}
]
end

Documentation

Documentation can be found at https://hexdocs.pm/is_type.