Results for “Functions & data types”
Small, practical examples. Search by task or narrow things down below.
Use a switch expression to classify a value
C#: Relational patterns express a small ordered range classification.
C#✓ Tested
Use case-insensitive dictionary keys
C#: Choose an ordinal comparer when case-insensitive keys represent identifiers.
C#✓ Tested
Use the first fulfilled promise result
TypeScript: Promise.any ignores individual rejections until one input fulfills.
TypeScript✓ Tested
Validate a finite numeric value without coercion
TypeScript: Number.isFinite rejects numeric strings as well as NaN and infinity.
TypeScript✓ Tested
Validate a whole ASCII identifier
TypeScript: Use an anchored expression without the multiline flag and reject a trailing line break explicitly.
TypeScript✓ Tested
Validate an argument at a method boundary
C#: ThrowIfNegative gives callers an explicit argument error for an invalid range.
C#✓ Tested
Verify a read-only volume rejects writes
Docker / Compose: A failed write confirms the mount’s read-only behavior.
Docker / Compose✓ Tested
Visit every item in a collection
TypeScript: Print each element in the collection’s original order.
TypeScript✓ Tested
Visit files recursively
Java: Close the stream returned by Files.walk and sort relative paths for stable output.
Java✓ Tested
Write a generic first-or-fallback helper
C#: Constrain a generic helper through its input shape and return an explicit caller-supplied fallback.
C#✓ Tested
Write and read binary bytes
Java: Use the byte-oriented Files methods when text encoding should not be involved.
Java✓ Tested
Write and read typed binary fields
Java: Data streams use a matching write/read order and fixed encodings for Java primitive values.
Java✓ Tested