1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2024-12-28 10:52:11 +00:00
mobilizon/lib/service/guards.ex
Thomas Citharel de047c8939
Various typespec and compilation improvements
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-09-26 17:52:20 +02:00

33 lines
668 B
Elixir

defmodule Mobilizon.Service.Guards do
@moduledoc """
Various guards
"""
@doc """
Returns `true` if `term` is a valid string and not empty.
## 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
end