must

abstract fun <T : KoBaseProvider> List<T>.must(predicate: (T) -> Boolean)(source)

Rejects the elements of this list that predicate answers false for.

Every rejected element becomes one entry in the report, named and located when Konsist can say where it is. An empty list rejects nothing and is not an error: a place that fills up over time holds no declarations until it does.

There is no Sequence overload. Konsist's sequence queries end with .toList(), and a constraint has to hold every rejection at once anyway to report them in walk order.

Example 1: every use case exposes invoke

"has an invoke function".konsist {
classes().withNameEndingWith("UseCase")
.must { klass -> klass.hasFunction { it.name == "invoke" } }
}

Example 2: a query that is not about classes

konsist {
functions().must { it.hasPublicOrDefaultModifier }
}

Parameters

predicate

what has to hold. true keeps the element, false rejects it.