Idiom
Composite Recipes
Recipes that include further recipes, often including the individual recipes below.
- Apply Kotlin null-safety and scope-function idioms
- Find cast and nullable-shape idioms
- Find collection null-safety idioms
- Find
let \{ \}ergonomics - Find manual null-check idioms
- Find null-assertion polish opportunities
- Find scope-function correctness swaps
Recipes
- Find
!!non-null assertions - Find
!!passed as a function argument - Find
?.apply \{ \}whose result is discarded - Find
?.let \{ it \}no-ops - Find
?.let \{ it.foo() \}that could use?.foo() - Find
?.let \{ \}calls at statement position - Find
also \{ \}blocks that mutate the receiver - Find
apply \{ \}blocks that perform no mutation - Find
checkNotNull(x)without an explanatory message - Find
filter \{ it != null \}.map \{ it!! \}chains - Find
firstOrNull \{ \} ?: error(...)patterns - Find
if (cond) value else nullpatterns - Find
if (x != null) x.foo()that could use?. - Find
if (x != null) y = x.foo()patterns - Find
if (x == null) return ...early-exit patterns - Find
if (x == null) throw ...patterns - Find
listOf(a, b, c).filterNotNull()patterns - Find long
?.safe-call chains - Find
map \{ ... \}.filterNotNull()chains - Find nested
let \{ \}chains - Find
obj.let \{ fn(it) \}whereobjis non-null - Find redundant
this.insideapply \{ \}blocks - Find
requireNotNull(x)without an explanatory message - Find
return nullin functions with nullable returns - Find
setOf(a, b, c).filterNotNull()patterns - Find
takeUnless \{ !p \}(double-negative) patterns - Find unsafe
ascasts - Find
with(x) \{ ... \}used as an expression - Find
x ?: throw SomeException()without a message - Find
x.run \{ ... \}that doesn't use the receiver - Find
x.takeIf \{ p \}?.let \{ ... \}patterns - Find
x?.firstOrNull()calls - Find
x?.let \{ \} ?: ypatterns - Find
x?.something.orEmpty()patterns