KT.UNNECESSARY_FILTER

Unnecessary 'filter()' call

Unnecessary filters add complexity to the code and accomplish nothing. They should be removed.

Noncompliant Code

Copy
val x = listOf(1, 2, 3)
    .filter { it > 1 }
    .count()

val x = listOf(1, 2, 3)
    .filter { it > 1 }
    .isEmpty()

Compliant Code

Copy
val x = listOf(1, 2, 3)
    .count { it > 2 }
}

val x = listOf(1, 2, 3)
    .none { it > 1 }

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html