CartItem.kt
Cart.kt
each
each { } runs its block on every element, and the path of an element is the path of the collection and its index:
items[0], coupons[2]. It works on any Iterable, such as a List or a Set, and on arrays. The block is a normal
block of constraints, so it can hold valid() for objects, or another each for a list of lists:
Maps
On a map,each runs on every entry, as a Map.Entry. Most rules are about only the keys or only the values, and two
shortcuts give the block the right type:
Every path uses the key, so a violation about a key and one about its value point at the same entry.
Rules about the collection
The constraints of the collection itself sit next toeach:
Size
minSize, maxSize, size, sizeBetween, notEmpty, emptyContent
contains, containsAll, containsAny, containsNone, distinct, distinctBycontainsKey, onlyKeys, containsValue and the size rules, which count
entries.
The order of the violations
Inside one property, the rules of the collection come first, then the violations of its elements, in the order of the elements. That is whydistinct comes before coupons[2] above.
Elements that can be null
In aList<String?>, an element can be null, and the block of each receives a String?, which the string
constraints do not accept. Check it with notNull():