Skip to main content
The constraints of a collection as a whole. The size rules work on any Collection, on arrays and on ByteArray; the content rules on List, Set and arrays. To check every element, use each.
A null argument checks nothing. A rule that reads a value that may be missing, such as max(customer.limit), never fails because of it: required on that value reports it once.
Playlist.kt

How many

minSize

minSize(min) on Collection, Array, ByteArray Checks that the collection has at least min elements. minSize

maxSize

maxSize(max) on Collection, Array, ByteArray Checks that the collection has at most max elements. maxSize

size

size(size) on Collection, Array, ByteArray Checks that the collection has exactly size elements. size

sizeBetween

sizeBetween(min, max) on Collection, Array, ByteArray Checks that the collection has between min and max elements, both included. sizeBetween

notEmpty

notEmpty() on Collection, Array, ByteArray Checks that the collection has at least one element. notEmpty

empty

empty() on Collection, Array, ByteArray Checks that the collection has no elements. empty

Content

contains

contains(element) on List, Set, Array Checks that the list contains element. contains

notContains

notContains(element) on List, Set, Array Checks that the list does not contain element. notContains

containsAll

containsAll(elements) on List, Set, Array Checks that the list contains every one of elements. containsAll

containsAny

containsAny(elements) on List, Set, Array Checks that the list contains at least one of elements. containsAny

containsNone

containsNone(elements) on List, Set, Array Checks that the list contains none of elements. containsNone

Duplicates

distinct

distinct() on Collection, Array Checks that the collection has no element twice, by equals. distinct

distinctBy

distinctBy(selector) on List, Set, Array Checks that no two elements of the list have the same key, as selector picks it. distinctBy