Assertions on elements of a collection

Some assertions on collections include sub-assertions applied to the elements of the collection. For example, we can assert that all elements conform to a repeated assertion.

val subject = setOf("catflap", "rubberplant", "marzipan")
expectThat(subject).all {
  isLowerCase()
  startsWith('c')
}

This produces the output:

▼ Expect that ["catflap", "rubberplant", "marzipan"]:
  ✗ all elements match:
    ▼ "catflap":
      ✓ is lower case
      ✓ starts with 'c'
    ▼ "rubberplant":
      ✓ is lower case
      ✗ starts with 'c'
              found 'r'
    ▼ "marzipan":
      ✓ is lower case
      ✗ starts with 'c'
              found 'm'

The results are broken down by individual elements in the collection so it's easy to see which failed.

Similarly, any asserts that at least one element passes the nested assertions and none succeeds if all elements of the collection fail the nested assertions.