OCaml Examples

OCamlOct 24, 2026

OCaml aligned plain-text table renderer

Measure column widths and print a pipe-separated table with right-padded cells that aligns in any terminal.

formattingtablecli
010
OCamlOct 24, 2026

OCaml bounded worker pool using Domain.spawn

Run independent tasks on a fixed number of OCaml 5 domains, collecting results and exceptions in one list.

concurrencypooldomains
000
OCamlOct 23, 2026

OCaml base64 encoder and validating decoder

Encode a string as standard Base64 and decode it back, validating length, padding and alphabet characters.

decodingencodingbase64
000
OCamlOct 23, 2026

OCaml input validation collecting field errors

Validate every field of an input record at once and return field names paired with human-readable messages.

recordserrorsvalidation
000
OCamlOct 23, 2026

OCaml flat JSON decoder with entry-index errors

Decode a flat JSON object into key/value pairs while reporting the failing entry index and offending text.

parsingerrorsjson
000
OCamlOct 23, 2026

OCaml percent-encode and split URL query strings

Percent-encode key/value pairs into a query string and split an incoming query string back into its pairs.

queryurlencoding
000
OCamlOct 23, 2026

OCaml GET JSON through curl with a hard timeout

Fetch JSON with curl and a hard timeout, then extract a named string field with clear error reporting.

httpjsontimeout
000
OCamlOct 23, 2026

OCaml environment config with typed validation

Read required and optional environment variables, parse integers, and return precise validation errors.

configenvvalidation
000
OCamlOct 23, 2026

OCaml token bucket rate limiter over Unix time

Allow short bursts up to a bucket size while enforcing an average request rate, using monotonic refill math.

token-bucketrate-limitunix
000
OCamlOct 23, 2026

OCaml bounded LRU cache on an association list

Keep the most recently used keys in a fixed-capacity association-list cache that drops the least recent entry.

mutablelrucache
000
OCamlOct 23, 2026

OCaml stable multi-key sort with nulls last

Sort records by city, then optional age with missing values last, then name, using a stable multi-key comparator.

sortrecordscomparator
000
OCamlOct 23, 2026

OCaml split a list into fixed-size batches

Split a list into consecutive batches of at most n items, preserving order and rejecting non-positive sizes.

listchunkbatch
000
OCamlOct 23, 2026

OCaml line-by-line file reader that closes its channel

Walk a text file line by line and collect its lines, closing the channel safely even if the callback raises.

linesfileio
000
OCamlOct 23, 2026

OCaml deep clone and recursive merge for config trees

Copy a nested tree of key/value nodes and deep-merge a patch into it, keeping the original untouched.

mergetreejson
000
OCamlOct 23, 2026

OCaml retry loop with capped exponential backoff

Run a fallible operation until it succeeds, sleeping with jittered exponential backoff capped at a fixed ceiling.

backoffretryjitter
000