The functions find(predicate)
, findLast(predicate)
, firstOrNull(predicate)
and "`lastOrNull(predicate)` can
be improperly used to check the presence of an element that matches the given predicate. In such cases the code is more difficult to read and
understand than it would be with the functions any(predicate)
, none(predicate)
or contains(element)
.
What is the potential impact?
The pattern of using find(predicate)
, findLast(predicate)
, firstOrNull(predicate)
and
"`lastOrNull(predicate)` combined with a null check, to check the presence of an element is not immediately clear to readers. For example, the
expression list.find { it > 5 } != null
is more difficult to understand than list.any { it > 5 }
. The additional
comparison operator increases the complexity of the expression and introduces confusion about the intent of the code.