fp-ts Quick Reference
When to Use
- You need help choosing between
Option, Either, Task, TaskEither, or related fp-ts types.
- The task is about imports, decision guidance, or selecting the right abstraction for a TypeScript flow.
- You want a compact reference for common fp-ts type choices and patterns.
Which Type Should I Use?
Is the operation async?
├─ NO: Does it involve errors?
│ ├─ YES → Either<Error, Value>
│ └─ NO: Might value be missing?
│ ├─ YES → Option<Value>
│ └─ NO → Just use the value
└─ YES: Does it involve errors?
├─ YES → TaskEither<Error, Value>
└─ NO: Might value be missing?
├─ YES → TaskOption<Value>
└─ NO → Task<Value>
Common Imports
// Core
import { pipe, flow } from 'fp-ts/function'
// Types
import * as O from 'fp-ts/Option' // Maybe exists
import * as E from 'fp-ts/Either' // Success or failure
import * as TE from 'fp-ts/TaskEither' // Async + failure
import * as T from 'fp-ts/Task' // Async (no failure)
import * as A from 'fp-ts/Array' // Array utilities
One-Line Patterns
| Need |
Code |
| Wrap nullable |
O.fromNullable(value) |
| Default value |
O.getOrElse(() => default) |
| Transform if exists |
O.map(fn) |
| Chain optionals |
O.flatMap(fn) |
| Wrap try/catch |
E.tryCatch(() => risky(), toError) |
| Wrap async |
TE.tryCatch(() => fetch(url), toError) |
| Run pipe |
pipe(value, fn1, fn2, fn3) |
Pattern Match
// Option
pipe(maybe, O.match(
() => 'nothing',
(val) => `got ${val}`
))
// Either
pipe(result, E.match(
(err) => `error: ${err}`,
(val) => `success: ${val}`
))
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.
1---2name: fp-types-ref3description: Quick reference for fp-ts types. Use when user asks which type to use, needs Option/Either/Task decision help, or wants fp-ts imports. 4category: AI & Agents5source: antigravity6tags: [typescript, ai]7url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/fp-types-ref8metadata:9 source: https://skillmd.com/skills/sickn33/fp-types-ref10---111213# fp-ts Quick Reference1415## When to Use16- You need help choosing between `Option`, `Either`, `Task`, `TaskEither`, or related fp-ts types.17- The task is about imports, decision guidance, or selecting the right abstraction for a TypeScript flow.18- You want a compact reference for common fp-ts type choices and patterns.1920## Which Type Should I Use?2122```23Is the operation async?24├─ NO: Does it involve errors?25│ ├─ YES → Either<Error, Value>26│ └─ NO: Might value be missing?27│ ├─ YES → Option<Value>28│ └─ NO → Just use the value29└─ YES: Does it involve errors?30 ├─ YES → TaskEither<Error, Value>31 └─ NO: Might value be missing?32 ├─ YES → TaskOption<Value>33 └─ NO → Task<Value>34```3536## Common Imports3738```typescript39// Core40import { pipe, flow } from 'fp-ts/function'4142// Types43import * as O from 'fp-ts/Option' // Maybe exists44import * as E from 'fp-ts/Either' // Success or failure45import * as TE from 'fp-ts/TaskEither' // Async + failure46import * as T from 'fp-ts/Task' // Async (no failure)47import * as A from 'fp-ts/Array' // Array utilities48```4950## One-Line Patterns5152| Need | Code |53|------|------|54| Wrap nullable | `O.fromNullable(value)` |55| Default value | `O.getOrElse(() => default)` |56| Transform if exists | `O.map(fn)` |57| Chain optionals | `O.flatMap(fn)` |58| Wrap try/catch | `E.tryCatch(() => risky(), toError)` |59| Wrap async | `TE.tryCatch(() => fetch(url), toError)` |60| Run pipe | `pipe(value, fn1, fn2, fn3)` |6162## Pattern Match6364```typescript65// Option66pipe(maybe, O.match(67 () => 'nothing',68 (val) => `got ${val}`69))7071// Either72pipe(result, E.match(73 (err) => `error: ${err}`,74 (val) => `success: ${val}`75))76```7778## Limitations79- Use this skill only when the task clearly matches the scope described above.80- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.81- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.