Scala Examples
Scala Base64 encode and validated decode
Encodes UTF-8 text to standard Base64 and decodes it back, returning an error instead of throwing on invalid input.
Scala plain-text table with aligned columns
Computes column widths and prints a padded fixed-width table with a header separator using only the standard library.
Scala signup validation with all field errors
Checks name, email, and age independently and returns every field-level error together instead of stopping at the first.
Scala URL query string builder and parser
Encodes key-value pairs as a UTF-8 query string and decodes them back, preserving empty values and treating plus as a space.
Scala bounded worker pool collecting failures
Runs tasks on a fixed-size thread pool and returns successful values alongside every captured exception.
Scala flat JSON decoder with clear errors
Parses a flat object of quoted string values without dependencies and reports malformed entries with context.
Scala HTTP JSON GET with hard timeouts
Performs a GET with connect and request timeouts, then extracts one top-level string field from the JSON body.
Scala environment config with typed validation
Reads required and optional environment variables with defaults, returning typed values or field-specific errors.
Scala token bucket rate limiter with bursts
Permits short bursts up to a fixed capacity while enforcing an average rate using monotonic clock time.
Scala bounded LRU cache with mutable map
Caches values with a fixed capacity, refreshing recency on every read and evicting the least recently used entry.
Scala stable multi-key sort with nulls last
Sorts records by age with nulls last, then by case-insensitive name, using a stable order-preserving sort.
Scala iterator chunking into fixed-size batches
Splits any Scala iterator into vectors of at most size elements, so large inputs never need to be materialized.
Scala line-by-line UTF-8 file reader
Reads a UTF-8 text file lazily, counting lines or returning the first N, with guaranteed resource closing.
Scala deep-clone and merge for a JSON tree
Immutably clones a JSON-like tree and recursively merges objects, preserving untouched values by deep copy.
Scala retry with capped exponential backoff
Retries a failing operation with capped exponential backoff and jitter, then rethrows the last exception.