Compose preconditions?
edman opened this issue · comments
Edman P. Anjos commented
Is there a way to compose multiple preconditions in a type?
@type non_empty_string :: String.t()
precond non_empty_string: &is_not_nil?/1
precond non_empty_string: &is_not_blank?/1
Ivan Rublev commented
Hey,
No. Only one precond
per type is supported. At the same time, it's possible to define a composite function like that:
@type non_empty_string :: String.t()
precond non_empty_string: &string_nonempty?/1
defp string_nonempty?(value) do: is_not_nil?(value) and is_not_blank?(value)
Domo fails if value
is not of the String.t()
type otherwise it passes the value to the local string_nonempty?/1
function and fails if the function's return value is of the false
or {:error, message}
shape. It succeeds for true
or :ok
return values.