FIND YOUR NEXT FEW LINES

Results for “Functions & parameter validation”

Small, practical examples. Search by task or narrow things down below.

202 snippets foundClear filters
GoFunctions & types

Accept a small behavior interface

Accept a small behavior interface using a complete Go program with explicit sample inputs.

Go✓ Tested
GoFunctions & types

Accept a variable number of arguments

Accept a variable number of arguments using a complete Go program with explicit sample inputs.

Go✓ Tested
RustFunctions & data types

Accept different types with a generic function

Accept different types with a generic function in a complete Rust program using the standard library.

Rust✓ Tested
Bash ScriptsParameter expansion

Assign a default to an empty or unset variable

Bash Scripts: The colon-equals expansion both supplies and assigns a fallback value.

Bash Scripts✓ Tested
GoFunctions & types

Attach behavior to a struct

Attach behavior to a struct using a complete Go program with explicit sample inputs.

Go✓ Tested
PythonFunctions & error handling

Avoid a shared mutable default argument

Python: Create a fresh list inside the function when the optional argument is omitted.

Python✓ Tested
JavaText validation & formatting

Build text efficiently in a loop

Java: Append to StringBuilder when constructing a string incrementally.

Java✓ Tested
C#Text validation & encoding

Build text incrementally with StringBuilder

C#: Append fragments instead of repeatedly concatenating intermediate strings in a loop.

C#✓ Tested
PythonFunctions & error handling

Cache repeated pure function calls

Python: Use lru_cache to avoid recomputing results for identical hashable arguments.

Python✓ Tested
JavaScriptNumbers & numeric validation

Calculate a page count with ceiling division

JavaScript: Use Math.ceil for a nonnegative item count and a positive page size.

JavaScript✓ Tested
TypeScriptNumbers & numeric validation

Calculate a page count with ceiling division

TypeScript: Use Math.ceil for a nonnegative item count and a positive page size.

TypeScript✓ Tested
JavaScriptNumbers & numeric validation

Calculate integers beyond Number’s precise range

JavaScript: Use BigInt operands together to avoid precision loss.

JavaScript✓ Tested