single-or-array-pattern
Installation
SKILL.md
Single-or-Array Pattern
Accept both single items and arrays, normalize at the top, process uniformly.
Quick Reference
function create(itemOrItems: T | T[]): Promise<Result<void, E>> {
const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
// ... implementation works on items array
}
The Structure
- Accept
T | T[]as the parameter type - Normalize with
Array.isArray()at the top of the function - All logic works against the array : one code path