ExUtils.Terms (ExUtils v1.0.1)

Copy Markdown View Source

Generic utilities for all Elixir terms

Summary

Functions

Evaluates if a value is blank.

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

Evaluates if a value is present.

Functions

blank?(str)

@spec blank?(any()) :: boolean()

Evaluates if a value is blank.

Returns true for nil, false, 0, empty strings, whitespace-only strings, empty lists, and empty maps.

Examples

iex> blank?(0)
true
iex> blank?(nil)
true
iex> blank?(false)
true
iex> blank?("")
true
iex> blank?("  ")
true
iex> blank?([])
true
iex> blank?(%{})
true
iex> blank?([1])
false
iex> blank?("Hello")
false

is_pure_map?(term)

@spec is_pure_map?(any()) :: boolean()

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

Example

iex> ExUtils.Terms.is_pure_map?(%{a: 1, b: 2})
true
iex> ExUtils.Terms.is_pure_map?(%URI{})
false

is_struct?(term)

@spec is_struct?(any()) :: boolean()

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

Example

iex> ExUtils.Terms.is_struct?(:atom)
false
iex> ExUtils.Terms.is_struct?(%{a: 1})
false
iex> ExUtils.Terms.is_struct?(%URI{})
true

present?(term)

@spec present?(any()) :: boolean()

Evaluates if a value is present.

This is the opposite of blank?/1.

Examples

iex> present?("Hello")
true
iex> present?(nil)
false