Skip to content

Latest commit

 

History

History
36 lines (23 loc) · 564 Bytes

UnnecessaryFilter.md

File metadata and controls

36 lines (23 loc) · 564 Bytes

Pattern: Unnecessary filter

Issue: -

Description

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 }

Further Reading