View Source Moar.Term (Moar v1.4.0)

Blank/present functions for terms.

A term is considered present when it is not blank.

A term is considered blank when:

  • it is nil
  • it is false
  • it is a string, and its length after being trimmed is 0
  • it is an empty list
  • it is an empty map

Link to this section Summary

Functions

Returns true if the term is blank, nil, or empty.

Returns the value if it is present (via present?), or else returns the default value.

Returns true if the term is not blank, nil, or empty.

Link to this section Functions

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

Returns true if the term is blank, nil, or empty.

iex> Moar.Term.blank?(nil)
true

iex> Moar.Term.blank?("   ")
true

iex> Moar.Term.blank?([])
true

iex> Moar.Term.blank?(%{})
true
Link to this function

presence(term, default \\ nil)

View Source
@spec presence(any(), any()) :: any()

Returns the value if it is present (via present?), or else returns the default value.

iex> Moar.Term.presence(20, 100)
20

iex> Moar.Term.presence(nil, 100)
100
@spec present?(any()) :: boolean()

Returns true if the term is not blank, nil, or empty.

iex> Moar.Term.present?(1)
true

iex> Moar.Term.present?([1])
true

iex> Moar.Term.present?(%{a: 1})
true

iex> Moar.Term.present?("1")
true