defmodule Requisito do @moduledoc """ Documentation for Requisito. """ @doc """ conform takes a predicate and a value and checks whether or not the value conforms to the predicate. ## Examples iex> Requisito.conform( &Integer.is_odd/1, 27) true iex> Requisito.conform( &Integer.is_odd/1, 30) :requisito_invalid """ @spec conform(fun(), any()) :: atom() | any() def conform(predicate, value) do if predicate.(value) do value else :requisito_invalid end end @doc """ valid? returns a boolean indicating whether or not a value is a property of a particular predicate. ## Examples iex> Requisito.valid?(&Integer.is_odd/1, 27) true iex> Requisito.valid?(&Integer.is_odd/1, 10) false """ @spec valid?(fun(), any()) :: boolean() def valid?(predicate, value) do property_result = predicate.(value) if is_boolean(property_result) do property_result else false end end end