View Source Moar.Term (Moar v1.62.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
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.
Returns present_value
when term
is present (via present?
), and blank_value
when term
is blank.
Functions
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
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
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
Returns present_value
when term
is present (via present?
), and blank_value
when term
is blank.
iex> Moar.Term.when_present(20, "continue", "value missing")
"continue"
iex> Moar.Term.when_present(nil, "continue", "value missing")
"value missing"