Pattern: Unnecessary filter
Issue: -
Unnecessary filters add complexity to the code and accomplish nothing. They should be removed.
Example of incorrect code:
val x = listOf(1, 2, 3)
.filter { it > 1 }
.count()
val x = listOf(1, 2, 3)
.filter { it > 1 }
.isEmpty()
Example of correct code:
val x = listOf(1, 2, 3)
.count { it > 2 }
}
val x = listOf(1, 2, 3)
.none { it > 1 }