KOTLIN / NOTES</>↗Kotlin25 Jun 2026
In Kotlin, you can use lazy evaluation mainly with: lazy { … } for lazily initialized properties Sequence for lazy collection-style pipelines Short-circuiting operators/functions like &&, ||, any, first, take Lambdas to defer expensive work until needed 1. Lazy property initialization with lazy Use lazy when a value is expensive to create and may not […]
KOTLIN / NOTES</>↗Kotlin25 Jun 2026
In Kotlin, custom collection transformations are often built with higher-order functions: functions that take other functions as parameters (lambdas) or return functions. Kotlin’s standard library already has transformations like map, filter, flatMap, groupBy, and fold, but you can build your own reusable transformations when your logic becomes domain-specific. 1. Basic higher-order transformation A simple custom […]
KOTLIN / NOTES</>↗Kotlin25 Jun 2026
In Kotlin, sequences let you process large collections lazily, which can reduce temporary allocations and improve performance for chained operations. The problem with regular collections Collection operations like map, filter, and flatMap are usually eager: val result = users .filter { it.isActive } .map { it.email } .take(10) With a List, Kotlin typically creates intermediate […]
KOTLIN / NOTES</>↗Kotlin24 Jun 2026
In Kotlin, read-only collection interfaces plus copy-on-write updates are a common way to model immutable-style data. Kotlin has two main collection interface families: Mutable Read-only MutableList<T> List<T> MutableSet<T> Set<T> MutableMap<K, V> Map<K, V> Read-only interfaces prevent mutation through that reference, while copy-on-write means you create a new collection when you need a changed version. Use […]
KOTLIN / NOTES</>↗Kotlin24 Jun 2026
In Kotlin, you can combine multiple collection operations by chaining functions like filter, map, sortedBy, take, groupBy, and others. Each operation returns a new collection, so you can call the next operation directly on the result. val numbers = listOf(1, 2, 3, 4, 5, 6) val result = numbers .filter { it % 2 == […]
KOTLIN / NOTES</>↗Kotlin24 Jun 2026
In Kotlin, destructuring lets you unpack values from an object into separate variables. It is commonly used with: Pair Map.Entry loops over maps lambda parameters Destructuring a Pair A Pair<A, B> contains two values: first and second. val pair = "Alice" to 25 val (name, age) = pair println(name) // Alice println(age) // 25 This […]