agentleFS
selamy-labsselamy-labs/agent-skills/skills/map-dispatch-over-conditionals/SKILL.md

map-dispatch-over-conditionals

Skill0 starsChanged 4 days agoMITView on GitHub

Use when stable named cases are implemented as long if or switch chains. Prefer table, map, or strategy dispatch with explicit fallback behavior.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when a conditional chain selects behavior by command, event type, status, provider, file kind, or another stable key.

    line 8
  2. Distinctive:

    Put validation and fallback behavior next to the dispatch lookup.

    line 16
  3. Distinctive:

    Keep each handler small and independently testable.

    line 17
  4. Distinctive:

    Add or update tests for one normal case, the fallback case, and any case with special authorization, side effects, or error handling.

    line 18

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Map Dispatch Over Conditionals

Use this skill when a conditional chain selects behavior by command, event type, status, provider, file kind, or another stable key.

Workflow

  1. Confirm the cases are named and stable. If each branch has unrelated conditions, simplify the branches first instead of forcing a table.
  2. Define a dispatch table from key to function, object, class, or value.
  3. Put validation and fallback behavior next to the dispatch lookup.
  4. Keep each handler small and independently testable.
  5. Add or update tests for one normal case, the fallback case, and any case with special authorization, side effects, or error handling.

Review Checks

  • Adding a new case changes one table entry and one focused test.
  • Unknown keys fail closed or use a documented default.
  • Handler signatures are consistent enough that the dispatch table is readable.
  • The table does not hide important ordering rules. If order matters, use an ordered structure and test it.

Anti-Patterns

  • Building a dispatch map for two tiny cases that were already clear.
  • Capturing too much outer state in anonymous handlers.
  • Replacing an obvious conditional with reflection, dynamic imports, or string evaluation.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.