filter is followed by a call that takes the same predicate itself

tx0/kotlin:filter-before-predicate-callstrictwarningperformance/algorithmicdepth fastperformance

What it finds

items.filter { it.ready }.first() builds a new list of every match to take one; items.first { it.ready } stops at the first. Likewise for firstOrNull, last, lastOrNull, single, singleOrNull, count, any and none.

From the rule's source, filter_then_terminal.rs.

Example from the rule's tests
fun pick(items: List<Item>): Item? {    val ready = items.filter { it.ready }.first()tx0 reports: filter { ... }.first() builds a list    val count = items.filter { it.ready }.count()tx0 reports: filter { ... }.count()    val all = items.filter { it.ready }.map { it.name }    return items.firstOrNull { it.ready }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:filter-before-predicate-call" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:filter-before-predicate-call] reason="..."

tx0 explain tx0/kotlin:filter-before-predicate-call shows the same in the terminal. Found a false positive? Report it.