fp-option-ref

Quick reference for Option type. Use when user needs to handle nullable values, optional data, or wants to avoid null checks.

31,392 stars
Complexity: easy

About this skill

The `fp-option-ref` skill serves as an on-demand knowledge base for the `Option` type from the `fp-ts` functional programming library. It encapsulates essential information and code examples for working with values that may or may not exist, represented as `Some(value)` or `None`. This skill empowers AI agents to generate robust TypeScript/JavaScript code, answer user queries about functional error handling, and explain complex concepts like `map`, `flatMap`, `fromNullable`, and `fromPredicate` in the context of `Option`. By leveraging this reference, agents can help users avoid common pitfalls associated with `null` or `undefined` checks, promoting cleaner, safer, and more predictable codebases.

Best use case

An AI agent can utilize this skill when a user asks for functional programming patterns to handle potentially missing data, needs examples of `fp-ts/Option` usage, or requires assistance in generating code that implements `Option` for safer data processing. It's particularly useful for explaining the benefits of `Option` over traditional null checks and demonstrating common transformations.

Quick reference for Option type. Use when user needs to handle nullable values, optional data, or wants to avoid null checks.

The AI agent will provide accurate explanations of the `fp-ts/Option` type, including its purpose, benefits, and core operations. It will also be able to generate correct and idiomatic TypeScript code snippets for creating and transforming `Option` values, effectively demonstrating how to handle nullable data in a functional manner.

Practical example

Example input

How can I use `fp-ts` to handle optional configuration values without null checks? Show me how to create and transform an `Option`.

Example output

The `fp-ts/Option` type is perfect for this! It represents a value that might or might not be present, helping you avoid `null` or `undefined` issues. Here's a quick reference:

**Option = A value that might not exist.** It can be `Some(value)` (value is present) or `None` (value is absent).

**1. Create an Option:**
```typescript
import * as O from 'fp-ts/Option'

O.some(5)              // Type: Option<number>, Value: Some(5)
O.none                 // Type: Option<never>, Value: None

// From potentially nullable values:
const maybeValue = Math.random() > 0.5 ? 'hello' : null;
O.fromNullable(maybeValue) // If maybeValue is 'hello' → Some('hello'), else → None

// From a predicate:
const num = 10;
O.fromPredicate((x: number) => x > 0)(num) // If num > 0 → Some(10), else → None
```

**2. Transform an Option:**
```typescript
import * as O from 'fp-ts/Option'

const five = O.some(5);
const none = O.none;

// O.map: Transforms the inner value if present. If None, it remains None.
O.map((x: number) => x * 2)(five) // Some(10)
O.map((x: number) => x * 2)(none) // None

// O.flatMap: Chains Options. Use when your transformation function also returns an Option.
// This prevents nested Options (e.g., Option<Option<T>>).
const safeDivide = (dividend: number, divisor: number): O.Option<number> => 
  divisor === 0 ? O.none : O.some(dividend / divisor);

O.flatMap((x: number) => safeDivide(x, 2))(five) // Some(2.5)
O.flatMap((x: number) => safeDivide(x, 0))(five) // None
O.flatMap((x: number) => safeDivide(x, 2))(none) // None

// O.filter: Returns None if the predicate is false, otherwise keeps the Some value.
O.filter((x: number) => x > 3)(five) // Some(5)
O.filter((x: number) => x > 10)(five) // None
```

When to use this skill

  • Use this skill when: - You need to generate TypeScript code that gracefully handles optional or nullable data using a functional programming paradigm. - You are explaining the `fp-ts/Option` type and its core operations (creation, transformation) to a user. - The goal is to avoid explicit `null` or `undefined` checks and improve code readability and safety. - You are refactoring existing code to incorporate `fp-ts` patterns for better error handling and data flow.

When not to use this skill

  • Avoid using this skill when: - The programming context does not involve `fp-ts` or functional programming concepts for optional data. - Simple `null` or `undefined` checks are sufficient for the task and `Option` would introduce unnecessary complexity. - The absence of a value signifies a critical error that should halt execution (e.g., throwing an exception) rather than being handled as a `None` value. - The task is unrelated to code generation, explanation of functional programming concepts, or data handling with `Option`.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/fp-option-ref/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/fp-option-ref/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/fp-option-ref/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How fp-option-ref Compares

Feature / Agentfp-option-refStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

Quick reference for Option type. Use when user needs to handle nullable values, optional data, or wants to avoid null checks.

Which AI agents support this skill?

This skill is designed for Claude.

How difficult is it to install?

The installation complexity is rated as easy. You can find the installation instructions above.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Option Quick Reference

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

```typescript
import * as O from 'fp-ts/Option'

O.some(5)              // Some(5)
O.none                 // None
O.fromNullable(x)      // null/undefined → None, else Some(x)
O.fromPredicate(x > 0)(x) // false → None, true → Some(x)
```

## Transform

```typescript
O.map(fn)              // Transform inner value
O.flatMap(fn)          // Chain Options (fn returns Option)
O.filter(predicate)    // None if predicate false
```

## Extract

```typescript
O.getOrElse(() => default)  // Get value or default
O.toNullable(opt)           // Back to T | null
O.toUndefined(opt)          // Back to T | undefined
O.match(onNone, onSome)     // Pattern match
```

## Common Patterns

```typescript
import { pipe } from 'fp-ts/function'
import * as O from 'fp-ts/Option'

// Safe property access
pipe(
  O.fromNullable(user),
  O.map(u => u.profile),
  O.flatMap(p => O.fromNullable(p.avatar)),
  O.getOrElse(() => '/default-avatar.png')
)

// Array first element
import * as A from 'fp-ts/Array'
pipe(
  users,
  A.head,  // Option<User>
  O.map(u => u.name),
  O.getOrElse(() => 'No users')
)
```

## vs Nullable

```typescript
// ❌ Nullable - easy to forget checks
const name = user?.profile?.name ?? 'Guest'

// ✅ Option - explicit, composable
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.

Related Skills

nft-standards

31392
from sickn33/antigravity-awesome-skills

Master ERC-721 and ERC-1155 NFT standards, metadata best practices, and advanced NFT features.

Web3 & BlockchainClaude

nextjs-app-router-patterns

31392
from sickn33/antigravity-awesome-skills

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

Web FrameworksClaude

new-rails-project

31392
from sickn33/antigravity-awesome-skills

Create a new Rails project

Code GenerationClaude

networkx

31392
from sickn33/antigravity-awesome-skills

NetworkX is a Python package for creating, manipulating, and analyzing complex networks and graphs.

Network AnalysisClaude

network-engineer

31392
from sickn33/antigravity-awesome-skills

Expert network engineer specializing in modern cloud networking, security architectures, and performance optimization.

Network EngineeringClaude

nestjs-expert

31392
from sickn33/antigravity-awesome-skills

You are an expert in Nest.js with deep knowledge of enterprise-grade Node.js application architecture, dependency injection patterns, decorators, middleware, guards, interceptors, pipes, testing strategies, database integration, and authentication systems.

Frameworks & LibrariesClaude

nerdzao-elite

31392
from sickn33/antigravity-awesome-skills

Senior Elite Software Engineer (15+) and Senior Product Designer. Full workflow with planning, architecture, TDD, clean code, and pixel-perfect UX validation.

Software DevelopmentClaude

nerdzao-elite-gemini-high

31392
from sickn33/antigravity-awesome-skills

Modo Elite Coder + UX Pixel-Perfect otimizado especificamente para Gemini 3.1 Pro High. Workflow completo com foco em qualidade máxima e eficiência de tokens.

Software DevelopmentClaudeGemini

native-data-fetching

31392
from sickn33/antigravity-awesome-skills

Use when implementing or debugging ANY network request, API call, or data fetching. Covers fetch API, React Query, SWR, error handling, caching, offline support, and Expo Router data loaders (useLoaderData).

API IntegrationClaude

n8n-workflow-patterns

31392
from sickn33/antigravity-awesome-skills

Proven architectural patterns for building n8n workflows.

Workflow AutomationClaude

n8n-validation-expert

31392
from sickn33/antigravity-awesome-skills

Expert guide for interpreting and fixing n8n validation errors.

Workflow AutomationClaude

n8n-node-configuration

31392
from sickn33/antigravity-awesome-skills

Operation-aware node configuration guidance. Use when configuring nodes, understanding property dependencies, determining required fields, choosing between get_node detail levels, or learning common configuration patterns by node type.

Workflow AutomationClaude