ExUtils v0.1.2 ExUtils

Collection of core Elixir utility methods that don’t fit in any specific Module

Summary

Functions

Checks if a Module exports a specific method

Checks if the term is a pure map (i.e. not a struct)

Checks if the term is a struct as well as a map

Functions

has_method?(module, method)
has_method?(module :: module, method :: atom | tuple :: {atom, number}) :: boolean

Checks if a Module exports a specific method

First argument must be a Module and the second argument can either be an :atom name of the function or a {:atom, arity} tuple

Example

ExUtils.has_method?(Map, :keys)         # => true
ExUtils.has_method?(Map, {:keys, 1})    # => true
ExUtils.has_method?(Map, {:keys, 2})    # => false
is_pure_map?(term)
is_pure_map?(term :: term) :: boolean

Checks if the term is a pure map (i.e. not a struct)

Example

ExUtils.is_pure_map?(%{a: 1, b: 2})          # => true
ExUtils.is_pure_map?(%Person{name: "Ali"})   # => false
is_struct?(term)
is_struct?(term :: term) :: boolean

Checks if the term is a struct as well as a map

Example

ExUnit.is_struct?(:atom)                  # => false
ExUnit.is_struct?(%{a: 1})                # => false
ExUnit.is_struct?(%Person{name: "Ali"})   # => true