Scala Examples

ScalaOct 23, 2026

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.

errorsencodingbase64
000
ScalaOct 23, 2026

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.

formattingtableterminalcli
000
ScalaOct 23, 2026

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.

eithererrorsvalidationforms
000
ScalaOct 23, 2026

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.

query-stringurlencodinghttp
000
ScalaOct 23, 2026

Scala bounded worker pool collecting failures

Runs tasks on a fixed-size thread pool and returns successful values alongside every captured exception.

concurrencyworker-poolerrorsexecutor
000
ScalaOct 23, 2026

Scala flat JSON decoder with clear errors

Parses a flat object of quoted string values without dependencies and reports malformed entries with context.

parsingerrorsvalidationjson
000
ScalaOct 23, 2026

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.

httpjsontimeouthttpclient
000
ScalaOct 23, 2026

Scala environment config with typed validation

Reads required and optional environment variables with defaults, returning typed values or field-specific errors.

environmentconfigurationeithervalidation
000
ScalaOct 23, 2026

Scala token bucket rate limiter with bursts

Permits short bursts up to a fixed capacity while enforcing an average rate using monotonic clock time.

concurrencytoken-bucketrate-limiting
000
ScalaOct 23, 2026

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.

mutablelrucachecollections
000
ScalaOct 23, 2026

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.

nullssortingcomparatorstable-sort
000
ScalaOct 23, 2026

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.

batchingiteratorcollections
000
ScalaOct 23, 2026

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.

streamingresourcesutf-8file-io
000
ScalaOct 23, 2026

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.

mergeimmutabilityjsondeep-clone
000
ScalaOct 23, 2026

Scala retry with capped exponential backoff

Retries a failing operation with capped exponential backoff and jitter, then rethrows the last exception.

resiliencebackoffretryjitter
000