← ClaudeAtlas

language-kotlinlisted

Kotlin idioms — null safety, coroutines, sealed interfaces, scope functions, and Flow. Auto-load when working with .kt files, build.gradle.kts, or when the user mentions Kotlin, coroutines, suspend, StateFlow, sealed interface, or Kotlin DSL.
lugassawan/swe-workbench · ★ 2 · Web & Frontend · score 68
Install: claude install-skill lugassawan/swe-workbench
# Kotlin ## Null safety - `?` makes nullability explicit in the type — `String?` vs `String`. - Safe-call `?.` returns null instead of throwing. Elvis `?:` provides a default. - **Never use `!!` in production code** — it is a promise you will never break that can't be verified. ```kotlin val length = name?.trim()?.length ?: 0 user?.email?.let { send(it) } // null-guard + scoping ``` ## Data classes and sealed interfaces - `data class` for value containers: auto-generates `equals`, `hashCode`, `toString`, `copy`, and destructuring. - `sealed interface` closes a hierarchy and enables exhaustive `when` without an `else` branch. ```kotlin sealed interface Result<out T> data class Success<T>(val value: T) : Result<T> data class Failure(val error: Throwable) : Result<Nothing> fun handle(r: Result<User>) = when (r) { is Success -> show(r.value) is Failure -> log(r.error) } ``` ## Coroutines — structured concurrency - `suspend` functions must be called from a coroutine or another `suspend` function. - Use `coroutineScope { }` for fan-out — child coroutines are cancelled if one fails. - `withContext(Dispatchers.IO)` for blocking IO; never block inside `Dispatchers.Default`. ```kotlin suspend fun fetchDashboard(id: String): Dashboard = coroutineScope { val user = async { fetchUser(id) } val orders = async { fetchOrders(id) } Dashboard(user.await(), orders.await()) } ``` - `launch` is fire-and-forget; `async` returns a `Deferred<T>`. - Prefer `coroutineSc