KOTLIN / CATATAN</>↗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 / CATATAN</>↗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 = […]
KOTLIN / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]