Results for “function”
Small, practical examples. Search by task or narrow things down below.
Observe command substitution’s trailing-newline removal
Bash Scripts: Command substitution removes trailing newlines while preserving embedded ones.
Bash Scripts✓ Tested
Parse a typed command-line option
Python: Use argparse to validate and convert an integer option.
Python✓ Tested
Pass a block of behavior as an argument
PowerShell: Invoke a scriptblock with the call operator and an explicit input value.
PowerShell✓ Tested
Preserve a failure after local cleanup
PowerShell: A bare throw inside catch rethrows the current exception.
PowerShell✓ Tested
Raise and catch a domain-specific exception
Python: Give a validation failure its own exception type so callers can handle it narrowly.
Python✓ Tested
Represent a small set of named states
C: An enum gives symbolic names to integer state values.
C✓ Tested
Return a collection as one pipeline object
PowerShell: The unary comma prevents the returned array from being enumerated at this boundary.
PowerShell✓ Tested
Return a status separately from a calculated result
C: An output pointer lets a function return success or failure independently of its numeric result.
C✓ Tested
Return a value through a named output variable
Bash Scripts: A Bash nameref can update a caller-supplied variable without command substitution.
Bash Scripts✓ Tested
Return an array through a nameref
Bash Scripts: Assign through a nameref to preserve array element boundaries.
Bash Scripts✓ Tested
Run cleanup after a caught exception
PowerShell: Use finally for cleanup that must occur after either success or failure.
PowerShell✓ Tested
Run cleanup around a custom context
Python: Use try/finally inside a contextmanager so cleanup runs even on failure.
Python✓ Tested