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---6
7# fp-ts Quick Reference
8
9## When to Use
10- 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.
13
14## Which Type Should I Use?
15
16```
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 value
23└─ 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```
29
30## Common Imports
31
32```typescript
33// Core
34import { pipe, flow } from 'fp-ts/function'
35
36// Types
37import * as O from 'fp-ts/Option' // Maybe exists
38import * as E from 'fp-ts/Either' // Success or failure
39import * as TE from 'fp-ts/TaskEither' // Async + failure
40import * as T from 'fp-ts/Task' // Async (no failure)
41import * as A from 'fp-ts/Array' // Array utilities
42```
43
44## One-Line Patterns
45
46| 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)` |
55
56## Pattern Match
57
58```typescript
59// Option
60pipe(maybe, O.match(
61 () => 'nothing',
62 (val) => `got ${val}`
63))
64
65// Either
66pipe(result, E.match(
67 (err) => `error: ${err}`,
68 (val) => `success: ${val}`
69))
70```
71
72## Limitations
73- 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.