Kotlin Examples
Aligned plain-text table renderer for the terminal
Renders headers and rows as a pipe-delimited text table padded per column for readable terminal and log output.
Base64 encode and validated decode helpers
Encodes UTF-8 text as Base64 and decodes it back, returning null for malformed input instead of throwing.
Field-level validation returning an error map
Validates email, age, and password and returns a field-to-message map instead of throwing on the first error.
Build and parse URL query strings in Kotlin
Percent-encodes a map into a query string and decodes one back into a map, tolerating missing equals signs and blank pairs.
Flat JSON object parser with pointed errors
Decodes a flat JSON object and throws a descriptive exception naming the bad entry, an empty key, or a duplicate key.
Fixed-size thread pool returning Kotlin Results
Runs each task on a fixed-size thread pool and returns one Result per task, so failures are collected instead of thrown.
Kotlin HTTP GET JSON field with timeouts
Performs an HTTP GET with connect and read timeouts, checks the status code, then scans a quoted field from the JSON body.
Typed environment config with validation errors
Reads environment variables with defaults, parses numbers, and fails fast with clear messages on invalid values.
Token bucket rate limiter with a refill clock
Allows short bursts up to the capacity while enforcing an average refill rate, using a synchronized acquire check.
Multi-key sort of nullable records with compareBy
Sorts records by age with nulls last, then by join date descending and finally by lowercase name, stably.
LinkedHashMap-backed LRU cache with size bound
A size-bounded LinkedHashMap that refreshes recency on read or write and evicts the least recently used entry.
Batch a Kotlin iterable into fixed-size lists
Groups iterable elements into lists of a fixed size, keeping order and returning a smaller final batch when needed.
Stream a file line by line with useLines
Reads a text file lazily line by line with useLines, closing the handle automatically even when an exception is thrown.
Deep clone and merge nested Kotlin maps
Recursively copies nested maps and lists, then merges a patch into a base map without mutating either input.
Kotlin retry loop with capped exponential backoff
Retries a block up to five times with capped exponential backoff and full jitter, sleeping only between attempts.