Results for “Functions & parameter validation”
Small, practical examples. Search by task or narrow things down below.
Validate an entire identifier
Python: Use fullmatch so a regex must consume the complete input.
Python✓ Tested
Validate an unknown value with a type guard
Check a field before treating unknown data as a typed object.
unknown✓ Tested
Validate UTF-8 bytes
Validate UTF-8 bytes using a complete Go program with explicit sample inputs.
Go✓ Tested
Wrap a value in a distinct type
Wrap a value in a distinct type in a complete Rust program using the standard library.
Rust✓ Tested
Wrap an error with context
Wrap an error with context using a complete Go program with explicit sample inputs.
Go✓ Tested
Write a generic slice helper
Write a generic slice helper using a complete Go program with explicit sample inputs.
Go✓ Tested
Yield values on demand
Python: Use a generator to produce a sequence without storing all intermediate values.
Python✓ Tested
Type a function’s inputs and output
Catch mismatched arguments during compilation.
function✓ Tested
Build a URL query string from values
JavaScript: URLSearchParams handles query escaping and repeated parameter appends.
JavaScript✓ Tested
Build a URL query string from values
TypeScript: URLSearchParams handles query escaping and repeated parameter appends.
TypeScript✓ Tested
Choose an action with switch
Map a small command value to a result.
switch✓ Tested
Consume positional arguments one at a time
Bash Scripts: Check the argument count before accessing the first parameter with nounset enabled.
Bash Scripts✓ Tested