pattern-match-on-option-and-either

pattern-match-on-option-and-either is a cursor rule for Cursor from PaulJPhilp/EffectPatterns. It costs 769 tokens per session, scanned A, original, MIT.

A TypeScript rule for handling values that may be missing or may contain an error by choosing a result for each possible case.

In plain words
What is it for?
Use it when displaying optional data or processing operations that can return either a valid result or an error.
Why use it?
It keeps success, failure, and missing-value logic visible instead of hiding it in nested conditionals.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when displaying optional data or processing operations that can return either a valid result or an error.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/pauljphilp/effectpatterns/pattern-match-on-option-and-either
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/PaulJPhilp/EffectPatterns

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pattern-match-on-option-and-either

README.md
[![agentmods](https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/pattern-match-on-option-and-either/github.svg)](https://agentmods.dev/rules/pauljphilp/effectpatterns/pattern-match-on-option-and-either)
Your own site
<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/pattern-match-on-option-and-either"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/pattern-match-on-option-and-either/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for pattern-match-on-option-and-either

Your own site · 80×15
<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/pattern-match-on-option-and-either"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/pattern-match-on-option-and-either.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 769 This file is loaded in full into every session.
When invoked 769 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00769 $0.00769
Opus 5.5 $0.00308 $0.00308
Sonnet 5.5 $0.00154 $0.00154
Haiku 4.5 $0.00077 $0.00077

Measured 2mo ago against content hash 0c39467ad244, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

pattern-match-on-option-and-either scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

content/published/rules/cursor/pattern-match-on-option-and-either.mdc · 105 lines

How it starts

The opening of the file, as written. The whole thing — 105 lines — stays where its author put it; the contents beside it link to each section on GitHub.

description: Use Option.match() and Either.match() for declarative pattern matching on optional and error-prone values globs: "**/*.ts" alwaysApply: true

Pattern Match on Option and Either

Rule: Use Option.match() and Either.match() for declarative pattern matching on optional and error-prone values

Example

Basic Option Matching

import { Option } from "effect";

const getUserName = (id: number): Option.Option<string> => {
  return id === 1 ? Option.some("Alice") : Option.none();
};

// Using .match() for declarative pattern matching
const displayUser = (id: number): string =>
  getUserName(id).pipe(
    Option.match({
      onNone: () => "Guest User",
      onSome: (name) => `Hello, ${name}!`,
    })
  );

console.log(displayUser(1));   // "Hello, Alice!"
console.log(displayUser(999)); // "Guest User"

Basic Either Matching

import { Either } from "effect";

const validateAge = (age: number): Either.Either<number, string> => {
  return age >= 18
    ? Either.right(age)
    : Either.left("Must be 18 or older");
};

// Using .match() for error handling
const processAge = (age: number): string =>
  validateAge(age).pipe(
    Either.match({
      onLeft: (error) => `Validation failed: ${error}`,
      onRight: (validAge) => `Age ${validAge} is valid`,
    })
  );

console.log(processAge(25)); // "Age 25 is valid"
console.log(processAge(15)); // "Validation failed: Must be 18 or older"

Advanced: Nested Matching

When dealing with nested Option and Either, use nested .match() calls:

import { Option, Either } from "effect";

interface UserProfile {
  name: string;
  age: number;
}

const getUserProfile = (
  id: number
): Option.Option<Either.Either<string, UserProfile>> => {
  if (id === 0) return Option.none(); // User not found
  if (id === 1) return Option.some(Either.left("Profile incomplete"));
  return Option.some(Either.right({ name: "Bob", age: 25 }));
};

// Nested matching - first on Option, then on Either
const displayProfile = (id: number): string =>
  getUserProfile(id).pipe(
    Option.match({
      onNone: () => "User not found",
      onSome: (result) =>
        result.pipe(
          Either.match({
            onLeft: (error) => `Error: ${error}`,
            onRight: (profile) => `${profile.name} (${profile.age})`,
          })
        ),
    })
  );

console.log(displayProfile(0)); // "User not found"
console.log(displayProfile(1)); // "Error: Profile incomplete"
console.log(displayProfile(2)); // "Bob (25)"

Read the full file on GitHub · 105 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 105 lines · 769 tokens per session scan A 0c39467ad244

Subscribe to this mod's changes

pattern-match-on-option-and-either is a cursor rule published in the GitHub repository PaulJPhilp/EffectPatterns (807 stars, last pushed 5mo ago), licensed MIT. It adds 769 tokens to every session, about $0.0031 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

pattern-match-on-option-and-either compared with cursor rules from other repositories

pattern-match-on-option-and-either next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
pattern-match-on-option-and-eitherPaulJPhilp/EffectPatternsCursor rule8075mo agoMITA769Cursor
typescript-code-generation-rulesWebDevPeterGriffin/The-VibeCode-BibleCursor rule4226d agononeA402Cursor
react-and-typescript-general-rulesWebDevPeterGriffin/The-VibeCode-BibleCursor rule4226d agononeA142Cursor
typescript-coding-styleWebDevPeterGriffin/The-VibeCode-BibleCursor rule4226d agononeA128Cursor
javascript-typescript-code-styleWebDevPeterGriffin/The-VibeCode-BibleCursor rule4226d agononeA88Cursor
typescript-usage-ruleWebDevPeterGriffin/The-VibeCode-BibleCursor rule4226d agononeA76Cursor
code-style-and-improvementsWebDevPeterGriffin/The-VibeCode-BibleCursor rule4226d agononeA104Cursor