General
single-or-array-pattern - Claude MCP Skill
Pattern for functions that accept either a single item or an array. Use when creating CRUD operations, batch processing APIs, or factory functions that should flexibly handle one or many inputs.
SEO Guide: Enhance your AI agent with the single-or-array-pattern tool. This Model Context Protocol (MCP) server allows Claude Desktop and other LLMs to pattern for functions that accept either a single item or an array. use when creating crud operation... Download and configure this skill to unlock new capabilities for your AI workflow.
Documentation
SKILL.md# Single-or-Array Overload Pattern
Accept both single items and arrays, normalize internally, delegate to array-only implementation.
## Quick Reference
```typescript
// Option 1: Explicit overloads (cleaner IDE signatures)
function create(item: T): Promise<Result<T, E>>;
function create(items: T[]): Promise<Result<T[], E>>;
function create(itemOrItems: T | T[]): Promise<Result<T | T[], E>> {
const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
return createInternal(items);
}
// Option 2: Union type (less boilerplate)
function create(itemOrItems: T | T[]): Promise<Result<void, E>> {
const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
// ... implementation
}
```
## The Structure
1. **Public API**: Accepts `T | T[]`
2. **Normalization**: `Array.isArray()` check, wrap single in array
3. **Internal function**: Only handles arrays
```typescript
// Public: flexible API
function createServer(clientOrClients: Client | Client[], options?: Options) {
const clients = Array.isArray(clientOrClients)
? clientOrClients
: [clientOrClients];
return createServerInternal(clients, options);
}
// Internal: array-only, all real logic here
function createServerInternal(clients: Client[], options?: Options) {
// Implementation only handles arrays
}
```
## Naming Conventions
| Parameter | Normalized Variable |
| ----------------------- | ------------------- |
| `recordingOrRecordings` | `recordings` |
| `clientOrClients` | `clients` |
| `itemOrItems` | `items` |
| `paramsOrParamsArray` | `paramsArray` |
## When to Use
**Good fit:**
- CRUD operations (create, update, delete)
- Batch processing APIs
- Factory functions accepting dependencies
- Any "do this to one or many" scenario
**Skip when:**
- Single vs batch have different semantics
- Return types vary significantly
- Array version needs different options
## Codebase Examples
### Server Factory (`packages/epicenter/src/server/server.ts`)
```typescript
function createServer(
client: AnyWorkspaceClient,
options?: ServerOptions,
): ReturnType<typeof createServerInternal>;
function createServer(
clients: AnyWorkspaceClient[],
options?: ServerOptions,
): ReturnType<typeof createServerInternal>;
function createServer(
clientOrClients: AnyWorkspaceClient | AnyWorkspaceClient[],
options?: ServerOptions,
) {
const clients = Array.isArray(clientOrClients)
? clientOrClients
: [clientOrClients];
return createServerInternal(clients, options);
}
```
### Database Service (`apps/whispering/src/lib/services/isomorphic/db/web.ts`)
```typescript
delete: async (recordingOrRecordings) => {
const recordings = Array.isArray(recordingOrRecordings)
? recordingOrRecordings
: [recordingOrRecordings];
const ids = recordings.map((r) => r.id);
return tryAsync({
try: () => db.recordings.bulkDelete(ids),
catch: (error) => DbServiceErr({ message: `Error deleting: ${error}` }),
});
},
```
### Query Mutations (`apps/whispering/src/lib/query/isomorphic/db.ts`)
```typescript
delete: defineMutation({
mutationFn: async (recordings: Recording | Recording[]) => {
const recordingsArray = Array.isArray(recordings)
? recordings
: [recordings];
for (const recording of recordingsArray) {
services.db.recordings.revokeAudioUrl(recording.id);
}
const { error } = await services.db.recordings.delete(recordingsArray);
if (error) return Err(error);
return Ok(undefined);
},
}),
```
## Anti-Patterns
### Don't: Separate functions for single vs array
```typescript
// Harder to maintain, users must remember two APIs
function createRecording(recording: Recording): Promise<...>;
function createRecordings(recordings: Recording[]): Promise<...>;
```
### Don't: Force arrays everywhere
```typescript
// Awkward for single items
createRecordings([recording]); // Ugly
```
### Don't: Duplicate logic in overloads
```typescript
// BAD: Logic duplicated
function create(item: T) {
return db.insert(item); // Duplicated
}
function create(items: T[]) {
return db.bulkInsert(items); // Different code path
}
// GOOD: Single implementation
function create(itemOrItems: T | T[]) {
const items = Array.isArray(itemOrItems) ? itemOrItems : [itemOrItems];
return db.bulkInsert(items); // One code path
}
```
## References
- [Full article](../../docs/articles/single-or-array-overload-pattern.md) — detailed explanation with more examplesSignals
Information
- Repository
- EpicenterHQ/epicenter
- Author
- EpicenterHQ
- Last Sync
- 1/26/2026
- Repo Updated
- 1/26/2026
- Created
- 1/12/2026
Reviews (0)
No reviews yet. Be the first to review this skill!
Related Skills
CLAUDE
Claude-Mem: AI Development Instructions
cursorrules
CrewAI Development Rules
firecrawl-build-onboarding
Get Firecrawl credentials and SDK setup into a project. Use when an application needs `FIRECRAWL_API_KEY`, when an agent should add Firecrawl to `.env`, when the user wants to authenticate Firecrawl for app code, or when choosing the first SDK and docs for a new Firecrawl integration. This skill includes its own browser auth flow, so it does not depend on the website onboarding skill.
firecrawl-build
Integrate Firecrawl into application code whenever a product, agent, or workflow needs web data inside the app — web search, live search results, page scraping, structured extraction, or browser interaction. Use when building any feature that needs data from the web in code, even if the user does not mention Firecrawl explicitly and only describes wanting web data, website content, search, scraping, or interaction in an application. Trigger for Firecrawl requests, "fire girl" shorthand, and generic app-level web-data needs that should map to `/scrape`, `/search`, or `/interact`. Do not use this skill for one-off terminal-only web tasks during the current session; use `firecrawl/cli` for those.
Related Guides
Bear Notes Claude Skill: Your AI-Powered Note-Taking Assistant
Learn how to use the bear-notes Claude skill. Complete guide with installation instructions and examples.
Mastering tmux with Claude: A Complete Guide to the tmux Claude Skill
Learn how to use the tmux Claude skill. Complete guide with installation instructions and examples.
OpenAI Whisper API Claude Skill: Complete Guide to AI-Powered Audio Transcription
Learn how to use the openai-whisper-api Claude skill. Complete guide with installation instructions and examples.