Various typespec and compilation improvements

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-09-10 11:27:59 +02:00
parent 029a4ea194
commit de047c8939
125 changed files with 790 additions and 357 deletions

View File

@@ -3,7 +3,31 @@ defmodule Mobilizon.Service.Guards do
Various guards
"""
defguard is_valid_string?(value) when is_binary(value) and value != ""
@doc """
Returns `true` if `term` is a valid string and not empty.
defguard is_valid_list?(value) when is_list(value) and length(value) > 0
## 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