KOTLIN / NOTES</>↗Kotlin01 Jul 2026
You combine scope functions with Kotlin DSLs by using each scope function for a clear role: apply {} to configure DSL objects also {} to log, validate, or attach side effects run {} to produce a final value let {} to transform intermediate values with {} to operate on an existing DSL context The most […]
KOTLIN / NOTES</>↗Kotlin30 Jun 2026
Design Kotlin APIs so that nullability communicates meaning, not uncertainty. A caller should be able to understand from the type alone whether a value is required, optional, absent, unknown, invalid, or failed. 1. Prefer non-null types by default Use nullable types only when null is a valid part of the API contract. fun sendEmail(address: String, […]
KOTLIN / NOTES</>↗Kotlin29 Jun 2026
Kotlin’s null safety works especially well with collections and maps because Kotlin lets you distinguish between: a nullable collection: List<String>? a collection containing nullable values: List<String?> both: List<String?>? The same idea applies to maps. 1. Nullable collection vs nullable elements val names: List<String>? = null val nicknames: List<String?> = listOf("Ana", null, "Sam") val maybeNicknames: List<String?>? […]
KOTLIN / NOTES</>↗Kotlin29 Jun 2026
In Kotlin, takeIf and takeUnless are scope-style functions used to keep or discard a value based on a condition. takeIf takeIf returns the object itself if the predicate is true; otherwise it returns null. val result = value.takeIf { condition } Equivalent to: val result = if (condition) value else null Example val number = […]
KOTLIN / NOTES</>↗Kotlin28 Jun 2026
In Kotlin, scope functions can be chained because each one returns either: the receiver object: also, apply the lambda result: let, run, with The key is understanding what each function returns. Common chaining pattern val result = User("Alice") .also { println("Created user: $it") } .apply { name = name.uppercase() } .let { "User name is […]
KOTLIN / NOTES</>↗Kotlin28 Jun 2026
Kotlin scope functions all do the same broad thing: they execute a block of code in the context of an object. The main differences are: How you refer to the object: this or it What the function returns: the object itself or the block result Quick decision table Function Object reference Returns Best for let […]