Skip to content

Files

Latest commit

 

History

History
26 lines (17 loc) · 539 Bytes

UseLet.md

File metadata and controls

26 lines (17 loc) · 539 Bytes

Pattern: Missing use of ?.let {}

Issue: -

Description

if expressions that either check for not-null and return null in the false case or check for null and returns null in the truthy case are better represented as ?.let {} blocks.

Example of incorrect code:

if (x != null) { x.transform() } else null
if (x == null) null else y

Example of correct code:

x?.let { it.transform() }
x?.let { y }

Further Reading