Results for “function”
Small, practical examples. Search by task or narrow things down below.
Keep function state between calls
C: A static local variable retains its stored value for the lifetime of the process.
C✓ Tested
Keep function-local assignments separate from caller state
PowerShell: Ordinary function assignments create local variables rather than replacing the caller’s variable.
PowerShell✓ Tested
Limit a beginner function variable to local scope
Bash Scripts: Limit a beginner function variable to local scope with a small standalone Bash program.
Bash Scripts✓ Tested
Load functions from a trusted local script
Bash Scripts: Source executes a file in the current shell so its function definitions remain available.
Bash Scripts✓ Tested
Pass a function as a callback
C: A typed function pointer permits behavior to be supplied to another function.
C✓ Tested
Pass behavior as a function delegate
C#: Func describes a callable with typed parameters and a return value.
C#✓ Tested
Preconfigure some function arguments
Python: Use partial to produce a callable with selected arguments already bound.
Python✓ Tested
Read positional parameters in a function
Bash Scripts: Read positional parameters in a function with a small standalone Bash program.
Bash Scripts✓ Tested
Restrict a function parameter to known choices
PowerShell: ValidateSet rejects unsupported values before the function body executes.
PowerShell✓ Tested
Return text from a shell function
Capture a function’s output with command substitution.
function✓ Tested
Return the first item with a generic function
Preserve the element type while allowing empty arrays.
generics✓ Tested
Return two values from a function
Return two values from a function using a complete Go program with explicit sample inputs.
Go✓ Tested