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 enprojectnment-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.4---56# fp-ts Quick Reference78## When to Use9- You need help choosing between `Option`, `Either`, `Task`, `TaskEither`, or related fp-ts types.10- The task is about imports, decision guidance, or selecting the right abstraction for a TypeScript flow.11- You want a compact reference for common fp-ts type choices and patterns.1213## Which Type Should I Use?1415```16Is the operation async?17├─ NO: Does it involve errors?18│ ├─ YES → Either<Error, Value>19│ └─ NO: Might value be missing?20│ ├─ YES → Option<Value>21│ └─ NO → Just use the value22└─ YES: Does it involve errors?23 ├─ YES → TaskEither<Error, Value>24 └─ NO: Might value be missing?25 ├─ YES → TaskOption<Value>26 └─ NO → Task<Value>27```2829## Common Imports3031```typescript32// Core33import { pipe, flow } from 'fp-ts/function'3435// Types36import * as O from 'fp-ts/Option' // Maybe exists37import * as E from 'fp-ts/Either' // Success or failure38import * as TE from 'fp-ts/TaskEither' // Async + failure39import * as T from 'fp-ts/Task' // Async (no failure)40import * as A from 'fp-ts/Array' // Array utilities41```4243## One-Line Patterns4445| Need | Code |46|------|------|47| Wrap nullable | `O.fromNullable(value)` |48| Default value | `O.getOrElse(() => default)` |49| Transform if exists | `O.map(fn)` |50| Chain optionals | `O.flatMap(fn)` |51| Wrap try/catch | `E.tryCatch(() => risky(), toError)` |52| Wrap async | `TE.tryCatch(() => fetch(url), toError)` |53| Run pipe | `pipe(value, fn1, fn2, fn3)` |5455## Pattern Match5657```typescript58// Option59pipe(maybe, O.match(60 () => 'nothing',61 (val) => `got ${val}`62))6364// Either65pipe(result, E.match(66 (err) => `error: ${err}`,67 (val) => `success: ${val}`68))69```7071## Limitations72- Use this skill only when the task clearly matches the scope described above.73- Do not treat the output as a substitute for enprojectnment-specific validation, testing, or expert review.74- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.