KOTLIN / NOTES</>↗Kotlin26 Jun 2026
In Kotlin, you declare a nullable variable by adding ? after the type. var name: String? = null This means name can hold either a String value or null. Examples: var age: Int? = null age = 25 val email: String? = "user@example.com" val phone: String? = null Without ?, Kotlin does not allow null: […]
KOTLIN / NOTES</>↗Kotlin26 Jun 2026
Kotlin handles null safety through its type system: a normal type like String cannot be null, while a nullable type like String? can be null. 1. Use nullable types when a value may be null val name: String = "Alice" // Cannot be null val nickname: String? = null // Can be null If a […]
KOTLIN / NOTES</>↗Kotlin26 Jun 2026
You typically combine Kotlin collections, coroutines, and Flow by using: collections for in-memory data coroutines for concurrency / async work Flow for asynchronous streams of values Basic idea If you have a collection: val ids = listOf(1, 2, 3, 4, 5) You can turn it into a Flow: val idFlow = ids.asFlow() Then process each […]
KOTLIN / NOTES</>↗Kotlin25 Jun 2026
In Kotlin, inline functions and reified type parameters are especially useful in collection processing when you want to write generic, type-safe utilities that still need access to the actual runtime type. Normally, generic type information is erased at runtime, but reified type parameters in inline functions let you do checks like is T, as T, […]
KOTLIN / NOTES</>↗Kotlin25 Jun 2026
Domain-specific collection extensions in Kotlin are usually extension functions or extension properties on Iterable<T>, List<T>, Set<T>, Map<K, V>, or more specific collection types that encode concepts from your domain. They let you write expressive code like: val overdueInvoices = invoices.overdue() val activeUsers = users.active() val totalRevenue = orders.totalRevenue() instead of repeatedly writing filtering, grouping, or […]
KOTLIN / NOTES</>↗Kotlin25 Jun 2026
To implement tail-recursive algorithms with collections in Kotlin, structure your function so that: The recursive call is the last operation Any intermediate result is carried in an accumulator The collection is processed by index, iterator-like state, or remaining sublist You mark the function with tailrec Basic pattern tailrec fun process( items: List<Int>, index: Int = […]