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.
git clone --depth 1 https://github.com/PaulJPhilp/EffectPatternsWrote 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.
[](https://agentmods.dev/rules/pauljphilp/effectpatterns/optional-pattern-2-optional-chaining-and-composition)<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/optional-pattern-2-optional-chaining-and-composition"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/optional-pattern-2-optional-chaining-and-composition/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.
<a href="https://agentmods.dev/rules/pauljphilp/effectpatterns/optional-pattern-2-optional-chaining-and-composition"><img src="https://agentmods.dev/badge/rules/pauljphilp/effectpatterns/optional-pattern-2-optional-chaining-and-composition.svg" alt="Reviewed on agentmods" width="80" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.02389 | $0.02389 |
| Opus 5.5 | $0.00956 | $0.00956 |
| Sonnet 5.5 | $0.00478 | $0.00478 |
| Haiku 4.5 | $0.00239 | $0.00239 |
Grade A, and why
optional-pattern-2-optional-chaining-and-composition 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.
How it starts
The opening of the file, as written. The whole thing — 350 lines — stays where its author put it; the contents beside it link to each section on GitHub.
description: Use Option combinators (map, flatMap, ap) to compose operations that may fail, creating readable and maintainable pipelines. globs: "**/*.ts" alwaysApply: true
Optional Pattern 2: Optional Chaining and Composition
Rule: Use Option combinators (map, flatMap, ap) to compose operations that may fail, creating readable and maintainable pipelines.
Example
This example demonstrates optional chaining patterns.
import { Effect, Option, pipe } from "effect";
interface User {
id: string;
name: string;
email: string;
}
interface Profile {
bio: string;
website?: string;
avatar?: string;
}
interface Settings {
theme: "light" | "dark";
notifications: boolean;
language: string;
}
const program = Effect.gen(function* () {
console.log(`\n[OPTIONAL CHAINING] Composing Option operations\n`);
// Example 1: Simple chain with map
console.log(`[1] Chaining transformations with map():\n`);
const userId: Option.Option<string> = Option.some("user-42");
const userDisplayId = Option.map(userId, (id) => `User#${id}`);
const idMessage = Option.match(userDisplayId, {
onSome: (display) => display,
onNone: () => "No user ID",
});
yield* Effect.log(`[CHAIN 1] ${idMessage}`);
// Chained maps
const email: Option.Option<string> = Option.some("[email protected]");
const emailParts = pipe(
email,
Option.map((e) => e.toLowerCase()),
Option.map((e) => e.split("@")),
Option.map((parts) => parts[0]) // username
);
const username = Option.getOrElse(emailParts, () => "unknown");
yield* Effect.log(`[USERNAME] ${username}\n`);
// Example 2: FlatMap for chaining operations that return Option
console.log(`[2] Chaining operations with flatMap():\n`);
const findUser = (id: string): Option.Option<User> =>
id === "user-42"
? Option.some({
id,
name: "Alice",
email: "[email protected]",
})
: Option.none();
const getProfile = (userId: string): Option.Option<Profile> =>
userId === "user-42"
? Option.some({
bio: "Software engineer",
website: "alice.dev",
avatar: "https://example.com/avatar.jpg",
})
: Option.none();
const userProfile = pipe(
Option.some("user-42"),
Option.flatMap((id) => findUser(id)),
Option.flatMap((user) => getProfile(user.id))
);
const profileInfo = Option.match(userProfile, {
onSome: (profile) => `Bio: ${profile.bio}, Website: ${profile.website}`,
onNone: () => "Profile not found",
});
yield* Effect.log(`[PROFILE] ${profileInfo}\n`);
// Example 3: Complex pipeline
console.log(`[3] Complex pipeline (user → profile → settings → theme):\n`);
const getSettings = (userId: string): Option.Option<Settings> =>
userId === "user-42"
? Option.some({
theme: "dark",
notifications: true,
language: "en",
})
: Option.none();
const userTheme = pipe(
Option.some("user-42"),
Option.flatMap((id) => findUser(id)),
Option.flatMap((user) => getSettings(user.id)),
Option.map((settings) => settings.theme)
);
const theme = Option.getOrElse(userTheme, () => "light");
yield* Effect.log(`[THEME] ${theme}`);
// Even if any step is None, result is None
const invalidUserTheme = pipe(
Option.some("invalid-user"),
Option.flatMap((id) => findUser(id)),
Option.flatMap((user) => getSettings(user.id)),
Option.map((settings) => settings.theme)
);
const invalidTheme = Option.getOrElse(invalidUserTheme, () => "light");
yield* Effect.log(`[DEFAULT THEME] ${invalidTheme}\n`);
// Example 4: Apply (ap) for combining independent Options
console.log(`[4] Combining values with ap():\n`);
const firstName: Option.Option<string> = Option.some("John");
const lastName: Option.Option<string> = Option.some("Doe");
// Create a function wrapped in Option
const combineNames = (first: string) => (last: string) =>
`${first} ${last}`;
const fullName = pipe(
Option.some(combineNames),
Option.ap(firstName),
Option.ap(lastName)
);
const name = Option.getOrElse(fullName, () => "Unknown");
yield* Effect.log(`[COMBINED] ${name}`);
// If any is None
const noLastName: Option.Option<string> = Option.none();
const incompleteName = pipe(
Option.some(combineNames),
Option.ap(firstName),
Option.ap(noLastName)
);
const incompleteFull = Option.getOrElse(incompleteName, () => "Incomplete");
yield* Effect.log(`[INCOMPLETE] ${incompleteFull}\n`);
// Example 5: Traverse for mapping over collections
console.log(`[5] Working with collections (traverse):\n`);
const userIds: string[] = ["user-42", "user-99", "user-1"];
// Try to load all users
const allUsers = Option.all(
userIds.map((id) => findUser(id))
);
const usersMessage = Option.match(allUsers, {
onSome: (users) => `Loaded ${users.length} users`,
onNone: () => "Some users not found",
});
yield* Effect.log(`[TRAVERSE] ${usersMessage}\n`);
// Example 6: Or/recovery with multiple options
console.log(`[6] Fallback chains with orElse():\n`);
const getPrimaryEmail = (): Option.Option<string> => Option.none();
const getSecondaryEmail = (): Option.Option<string> =>
Option.some("[email protected]");
const getTertiaryEmail = (): Option.Option<string> =>
Option.some("[email protected]");
const email1 = pipe(
getPrimaryEmail(),
Option.orElse(() => getSecondaryEmail()),
Option.orElse(() => getTertiaryEmail())
);
const contactEmail = Option.getOrElse(email1, () => "[email protected]");
yield* Effect.log(`[FALLBACK] Using email: ${contactEmail}\n`);
// Example 7: Filtering options
console.log(`[7] Filtering with predicates:\n`);
const age: Option.Option<number> = Option.some(25);
const canVote = pipe(
age,
Option.filter((a) => a >= 18)
);
const voteStatus = Option.match(canVote, {
onSome: () => "Can vote",
onNone: () => "Too young to vote",
});
yield* Effect.log(`[FILTER] ${voteStatus}`);
// Multiple filters in chain
const score: Option.Option<number> = Option.some(85);
const isAGrade = pipe(
score,
Option.filter((s) => s >= 80),
Option.filter((s) => s < 90)
);
const grade = Option.match(isAGrade, {
onSome: () => "Grade A",
onNone: () => "Not in A range",
});
yield* Effect.log(`[GRADES] ${grade}\n`);
// Example 8: Practical: Database query chain
console.log(`[8] Real-world: Database record chain:\n`);
const getRecord = (id: string): Option.Option<{ data: string; nested: { value: number } }> =>
id === "rec-1"
? Option.some({
data: "content",
nested: { value: 42 },
})
: Option.none();
const recordValue = pipe(
Option.some("rec-1"),
Option.flatMap((id) => getRecord(id)),
Option.map((rec) => rec.nested),
Option.map((nested) => nested.value),
Option.map((value) => value * 2)
);
const finalValue = Option.getOrElse(recordValue, () => 0);
yield* Effect.log(`[VALUE] ${finalValue}`);
// Missing record
const missingValue = pipe(
Option.some("rec-999"),
Option.flatMap((id) => getRecord(id)),
Option.map((rec) => rec.nested),
Option.map((nested) => nested.value),
Option.map((value) => value * 2)
);
const defaultValue = Option.getOrElse(missingValue, () => 0);
yield* Effect.log(`[DEFAULT] ${defaultValue}\n`);
// Example 9: Conditional chaining
console.log(`[9] Conditional paths:\n`);
const loadUserWithFallback = (id: string) =>
pipe(
findUser(id),
Option.flatMap((user) =>
// Only get premium features if user exists
user.name.includes("Alice")
? Option.some({ ...user, isPremium: true })
: Option.none()
),
Option.orElse(() =>
// Fallback: return basic user
findUser(id)
)
);
const result1 = loadUserWithFallback("user-42");
const result2 = loadUserWithFallback("user-99");
yield* Effect.log(
`[CONDITIONAL 1] ${Option.match(result1, { onSome: (u) => `${u.name}`, onNone: () => "Not found" })}`
);
yield* Effect.log(
`[CONDITIONAL 2] ${Option.match(result2, { onSome: (u) => `${u.name}`, onNone: () => "Not found" })}`
);
});
Effect.runPromise(program);
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.
- 2mo ago First seen · 350 lines · 2,389 tokens per session scan A f04f894e0b5a
optional-pattern-2-optional-chaining-and-composition is a cursor rule published in the GitHub repository PaulJPhilp/EffectPatterns (807 stars, last pushed 5mo ago), licensed MIT. It adds 2,389 tokens to every session, about $0.0096 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.
optional-pattern-2-optional-chaining-and-composition compared with cursor rules from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| optional-pattern-2-optional-chaining-and-compositionPaulJPhilp/EffectPatterns | Cursor rule | 807 | 5mo ago | MIT | A | 2,389 | Cursor |
| typescript-code-generation-rulesWebDevPeterGriffin/The-VibeCode-Bible | Cursor rule | 42 | 26d ago | none | A | 402 | Cursor |
| react-and-typescript-general-rulesWebDevPeterGriffin/The-VibeCode-Bible | Cursor rule | 42 | 26d ago | none | A | 142 | Cursor |
| typescript-coding-styleWebDevPeterGriffin/The-VibeCode-Bible | Cursor rule | 42 | 26d ago | none | A | 128 | Cursor |
| javascript-typescript-code-styleWebDevPeterGriffin/The-VibeCode-Bible | Cursor rule | 42 | 26d ago | none | A | 88 | Cursor |
| typescript-usage-ruleWebDevPeterGriffin/The-VibeCode-Bible | Cursor rule | 42 | 26d ago | none | A | 76 | Cursor |
| code-style-and-improvementsWebDevPeterGriffin/The-VibeCode-Bible | Cursor rule | 42 | 26d ago | none | A | 104 | Cursor |