View Source Bond.Predicates (Bond v0.8.3)

Predicate functions and operators that are useful in assertions and contract specifications.

This module is automatically imported for all assertion expressions, specifically in preconditions defined with @pre, postconditions defined with @post, and in uses of Bond.check/1 or Bond.check/2.

To use the infix operator versions of the predicates in other contexts, this module must be imported in the using module.

Summary

Functions

Pattern matching operator: equivalent to match?(pattern, expression).

Logical implication: does p imply q?

Logical exclusive or: is either p or q true, but not both?

Logical exclusive or operator: p ||| q means xor(p, q).

Logical implication operator: p ~> q means implies?(p, q).

Functions

Link to this macro

pattern <~ expression

View Source (macro)

Pattern matching operator: equivalent to match?(pattern, expression).

Examples

iex> {:ok, %Date{}} <~ Date.new(1974, 6, 6) 
true
iex> {:error, _} <~ Date.new(-1, -1, -1)
true
@spec implies?(boolean(), boolean()) :: boolean()

Logical implication: does p imply q?

For an infix operator version of logical implication see ~>/2.

Examples

iex> implies?(true, true)
true
iex> implies?(true, false)
false
iex> implies?(false, true)
true
iex> implies?(false, false)
true
@spec xor(boolean(), boolean()) :: boolean()

Logical exclusive or: is either p or q true, but not both?

For an infix operator version of exclusive or see |||/2.

Examples

iex> xor(true, true)
false
iex> xor(true, false)
true
iex> xor(false, true)
true
iex> xor(false, false)
false

Logical exclusive or operator: p ||| q means xor(p, q).

Note that the ||| operator has higher precedence than many other operators and it may be necessary to parenthesize the expressions on either side of the operator to get the expected result.

Examples

iex> true ||| true
false
iex> true ||| false
true
iex> false ||| true
true
iex> false ||| false
false
iex> x = 2
2
iex> y = 4
4
iex> (x - y < 0) ||| (y <= x)
true

Logical implication operator: p ~> q means implies?(p, q).

Note that the ~> operator has higher precedence than many other operators and it may be necessary to parenthesize the expressions on either side of the operator to get the expected result.

Examples

iex> true ~> true
true
iex> true ~> false
false
iex> false ~> true
true
iex> false ~> false
true
iex> x = 2
2
iex> y = 4
4
iex> (x - y < 0) ~> (y > x)
true