| name | fp-option-ref |
| description | ALWAYS use this when the user mentions FP Option REF, asks to build, debug, review, document, automate, test, configure, migrate, or make decisions in this domain, or the task clearly depends on FP Option REF; scope: Quick reference for Option type. Apply the bundled workflow, references, scripts, Senior Master standard, and Codex strict review gate before final output. |
Option Quick Reference
Selective Reading Rule
Start with:
references/senior-master-standard.md
references/usage-routing.md
references/quality-checklist.md
Then load only the inherited docs, scripts, assets, or examples that match the user's actual task.
Option = value that might not exist. Some(value) or None.
When to Use
- You need a quick fp-ts reference for nullable or optional values.
- The task involves eliminating null checks, safe property access, or optional chaining with
Option.
- You want a short reference card rather than a full migration guide.
Create
import * as O from 'fp-ts/Option'
O.some(5)
O.none
O.fromNullable(x)
O.fromPredicate(x > 0)(x)
Transform
O.map(fn)
O.flatMap(fn)
O.filter(predicate)
Extract
O.getOrElse(() => default)
O.toNullable(opt)
O.toUndefined(opt)
O.match(onNone, onSome)
Common Patterns
import { pipe } from 'fp-ts/function'
import * as O from 'fp-ts/Option'
pipe(
O.fromNullable(user),
O.map(u => u.profile),
O.flatMap(p => O.fromNullable(p.avatar)),
O.getOrElse(() => '/default-avatar.png')
)
import * as A from 'fp-ts/Array'
pipe(
users,
A.head,
O.map(u => u.name),
O.getOrElse(() => 'No users')
)
vs Nullable
const name = user?.profile?.name ?? 'Guest'
pipe(
O.fromNullable(user),
O.flatMap(u => O.fromNullable(u.profile)),
O.map(p => p.name),
O.getOrElse(() => 'Guest')
)
Use Option when you need to chain operations on optional values.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.