2020-07-31 17:52:26 +02:00
|
|
|
defmodule Mobilizon.Service.Guards do
|
|
|
|
@moduledoc """
|
|
|
|
Various guards
|
|
|
|
"""
|
|
|
|
|
2021-09-10 11:27:59 +02:00
|
|
|
@doc """
|
|
|
|
Returns `true` if `term` is a valid string and not empty.
|
2020-08-03 17:34:50 +02:00
|
|
|
|
2021-09-10 11:27:59 +02:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> is_valid_string("one")
|
|
|
|
true
|
|
|
|
iex> is_valid_string("")
|
|
|
|
false
|
|
|
|
iex> is_valid_string(2)
|
|
|
|
false
|
|
|
|
"""
|
|
|
|
defguard is_valid_string(term) when is_binary(term) and term != ""
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Returns `true` if `term` is a valid list and not empty.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
iex> is_valid_list(["one"])
|
|
|
|
true
|
|
|
|
iex> is_valid_list([])
|
|
|
|
false
|
|
|
|
iex> is_valid_list("foo")
|
|
|
|
false
|
|
|
|
"""
|
|
|
|
defguard is_valid_list(term) when is_list(term) and length(term) > 0
|
2020-07-31 17:52:26 +02:00
|
|
|
end
|