Results for “generic”
Small, practical examples. Search by task or narrow things down below.
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
Build a mutable generic list
PowerShell: A generic list supports repeated additions without copying an entire array each time.
PowerShell✓ Tested
Return the first item with a generic function
Preserve the element type while allowing empty arrays.
generics✓ 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 a generic slice helper
Write a generic slice helper using a complete Go program with explicit sample inputs.
Go✓ Tested
Read a property with keyof
Keep the key and returned value tied to an object type.
keyof✓ Tested
Append an item to a small array
PowerShell: The plus-equals operator builds a new array; use a generic list for repeated large additions.
PowerShell✓ Tested
Apply an operation to a variant’s active value
C++: A generic visitor lets the compiler check behavior for every possible alternative.
C++✓ Tested