General functions

The following table describes the general functions.

Warning Using negation (!) at the beginning of any function can cause unexpected validation results.
Function Description
isEmpty (value) Checks whether the value is empty, null, or doesn't contain any element.
isNotEmpty (value) Checks whether the value isn't empty.
isEqual (value1, value2) Checks whether the first value is the same as the second value.
isNotEqual (value1, value2) Checks whether the value isn't the same as the second value.
isIn (value, Collection) Checks whether the value is part of a collection.
areIn (Collection values, Collection collection) Checks whether the collection is part of another collection.
isAny (Collection, Closure) Checks whether any value in a collection meets the criteria of a validation closure.
isEvery (Collection, Closure) Checks whether all values in a collection meet the criteria of a validation closure.
isFalse (value)

Checks whether the value is false, empty, or null according to the Groovy truth.

Examples:

  • isFalse (something) returns true if something is false.
  • isFalse (something) returns false if something is true.
  • isFalse (false) returns true.
  • isFalse (null) returns true.
isTrue (value)

Checks whether the value is true, empty, or null according to the Groovy truth.

Examples:

  • isTrue (something) returns false if something is false.
  • isTrue (something) returns true if something is true.
  • isTrue (false) returns false.
  • isTrue (null) returns true.
isUnique (Collection, Closure)

Checks whether all values in a collection are unique.

Examples:

  • isUnique ([1,2,3]) returns true.
  • isUnique ([1,2,3,1]) returns false.

The closure {it % 2} allows only one even and one odd element in the list.

  • isUnique ([3, 4], {it % 2}) returns true.
  • isUnique ([1, 3, 4], {it % 2}) returns false because both 1 and 3 are odd.
validate (value)

Checks whether the value is a valid function, accepting any closure that is capable of returning true or false.

validate (value) is a general validation function used to check another function.