Do you prefer: `filter { it.id != id }` vs `filter...
# getting-started
m
Do you prefer:
filter { it.id != id }
vs
filterNot { it.id == id }
? I find myself rarely using the
*Not
variants of stdlib functions because it's longer than just inverting the predicate inside, and is also sligthly harder to read because you have to read the original predicate only to have to invert it in your mind. Only cases where I find them useful is when passing in a function reference (
filterNot(::predicate)
).
1️⃣ 3
j
Same for me. I also sometimes use
filterNot
when the predicate is just
it.isSomeBooleanProperty
d
I use such
*Not
functions, because it’s harder to overlook while scanning code. Together with function references it’s powerful to describe your intend from domain perspective.