Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Kotlin Backing Fields with Custom get/set
`field` is the implicit backing storage inside a property's getter/setter. Lets you wrap simple storage with validation, normalization, or change tracking — without writing a separate private field.
Kotlin takeIf / takeUnless — Conditional Pipelines
`takeIf { predicate }` returns `this` if the predicate holds, else null. `takeUnless` is the inverse. Combine with `?.let { ... }` for clean conditional transformations.
Kotlin Type-Safe Builder DSL
`@DslMarker` + lambdas with receivers let you build statically-typed DSLs that look like declarative configuration. The HTML / Gradle Kotlin DSL style.
Kotlin Property Delegation by Map
Delegate a property to a `Map<String, V>` — reading the property fetches by name; writing stores by name. Quick way to back a class with a config map.
Kotlin observable — Listen for Property Changes
`Delegates.observable(initial) { prop, old, new -> ... }` fires a callback every time the property changes. Useful for state-tracking, simple observability without a full reactive lib.
Kotlin Compose Modifier Chain
`Modifier` is how you customize composables — padding, click handlers, background, size, alignment. Order matters: each modifier wraps the previous one.
Kotlin ViewModel + StateFlow + Compose
Standard Android pattern: ViewModel holds state in a `StateFlow`, Compose collects it as state. Survives config changes; isolates business logic from UI.
Kotlin Jetpack Compose — Basic Composable
Compose is Android's modern declarative UI toolkit. A `@Composable` function describes UI; the runtime re-runs it when inputs change. Replaces XML layouts entirely.
Kotlin JSON Annotations — Rename, Default, Optional
Per-field annotations let you map Kotlin camelCase ↔ JSON snake_case, set defaults for missing fields, and skip nulls.
Kotlin StateFlow — Observable State
`StateFlow<T>` is a hot Flow holding a single current value. Perfect for UI state in Compose/Android — always has a value, conflates intermediate values, multi-subscriber.
Kotlin async / await for Parallel Results
`async` returns a `Deferred<T>` — like a Future. Use it when you need a RESULT back, in parallel. Call `.await()` to get the value (suspends until ready).
Kotlin Coroutines — suspend Function Basics
`suspend fun` can be paused and resumed without blocking a thread. Call only from another `suspend` function or a coroutine builder (`launch`, `runBlocking`, `async`).
Kotlin minOf / maxOf / sumOf / averageOf
Numerical reducers with a selector lambda — much cleaner than `.map { ... }.max()` chains. `sumOf` is type-aware (returns Int, Long, Double, BigDecimal as appropriate).
Kotlin Sorting Collections
`sortedBy { ... }` returns a sorted copy. `sortedWith(compareBy { ... })` chains tie-breakers cleanly. Avoid `sortBy` (in-place) on read-only lists.
Kotlin windowed and chunked
`chunked(n)` splits a list into NON-overlapping pieces of size n. `windowed(n)` slides a fixed-size window across — overlapping. Useful for moving averages, n-grams, batch APIs.
Kotlin flatMap and Flattening
`flatMap` maps each item to a collection, then concatenates. Use it when "for each X, produce N Y's, collect all Y's". `flatten()` is the no-mapping version.
Kotlin Local Functions
Functions can be declared inside other functions. Closures over outer scope let you eliminate parameter-threading. Use sparingly — too many nested locals hurts readability.
Kotlin inline Functions — Zero-Cost Lambdas
`inline fun` copies the body (including lambda bodies) into the call site at compile time. Result: no `Function` object allocated for the lambda; `return` from inside the lambda exits the enclosing function.