IvanRublev / Domo

A library to validate values of nested structs with their type spec t() and associated precondition functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compose preconditions?

edman opened this issue · comments

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

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.