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.4license: MIT5---67# fp-ts Quick Reference89## When to Use10- You need help choosing between `Option`, `Either`, `Task`, `TaskEither`, or related fp-ts types.11- The task is about imports, decision guidance, or selecting the right abstraction for a TypeScript flow.12- You want a compact reference for common fp-ts type choices and patterns.1314## Which Type Should I Use?1516```17Is the operation async?18├─ NO: Does it involve errors?19│ ├─ YES → Either<Error, Value>20│ └─ NO: Might value be missing?21│ ├─ YES → Option<Value>22│ └─ NO → Just use the value23└─ YES: Does it involve errors?24 ├─ YES → TaskEither<Error, Value>25 └─ NO: Might value be missing?26 ├─ YES → TaskOption<Value>27 └─ NO → Task<Value>28```2930## Common Imports3132```typescript33// Core34import { pipe, flow } from 'fp-ts/function'3536// Types37import * as O from 'fp-ts/Option' // Maybe exists38import * as E from 'fp-ts/Either' // Success or failure39import * as TE from 'fp-ts/TaskEither' // Async + failure40import * as T from 'fp-ts/Task' // Async (no failure)41import * as A from 'fp-ts/Array' // Array utilities42```4344## One-Line Patterns4546| Need | Code |47|------|------|48| Wrap nullable | `O.fromNullable(value)` |49| Default value | `O.getOrElse(() => default)` |50| Transform if exists | `O.map(fn)` |51| Chain optionals | `O.flatMap(fn)` |52| Wrap try/catch | `E.tryCatch(() => risky(), toError)` |53| Wrap async | `TE.tryCatch(() => fetch(url), toError)` |54| Run pipe | `pipe(value, fn1, fn2, fn3)` |5556## Pattern Match5758```typescript59// Option60pipe(maybe, O.match(61 () => 'nothing',62 (val) => `got ${val}`63))6465// Either66pipe(result, E.match(67 (err) => `error: ${err}`,68 (val) => `success: ${val}`69))70```7172## Limitations73- Use this skill only when the task clearly matches the scope described above.74- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.75- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.