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-ref
3description: "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."
4version: 1.0.0
5author:
6 name: "sickn33 / Antigravity Community"
7 github: sickn33
8tags: [types, ref, development]
9category: development
10platforms: [macos, linux, windows]
11license: MIT
12metadata:
13 hermes:
14 source: https://skillmd.com/skills/nous-hermeshub/fp-types-ref
15 upstream: "antigravity-awesome-skills"
16 risk: "safe"
17 original_author: "Antigravity Community"
18---
19
20# fp-ts Quick Reference
21
22## When to Use
23- You need help choosing between `Option`, `Either`, `Task`, `TaskEither`, or related fp-ts types.
24- The task is about imports, decision guidance, or selecting the right abstraction for a TypeScript flow.
25- You want a compact reference for common fp-ts type choices and patterns.
26
27## Which Type Should I Use?
28
29```
30Is the operation async?
31├─ NO: Does it involve errors?
32│ ├─ YES → Either<Error, Value>
33│ └─ NO: Might value be missing?
34│ ├─ YES → Option<Value>
35│ └─ NO → Just use the value
36└─ YES: Does it involve errors?
37 ├─ YES → TaskEither<Error, Value>
38 └─ NO: Might value be missing?
39 ├─ YES → TaskOption<Value>
40 └─ NO → Task<Value>
41```
42
43## Common Imports
44
45```typescript
46// Core
47import { pipe, flow } from 'fp-ts/function'
48
49// Types
50import * as O from 'fp-ts/Option' // Maybe exists
51import * as E from 'fp-ts/Either' // Success or failure
52import * as TE from 'fp-ts/TaskEither' // Async + failure
53import * as T from 'fp-ts/Task' // Async (no failure)
54import * as A from 'fp-ts/Array' // Array utilities
55```
56
57## One-Line Patterns
58
59| Need | Code |
60|------|------|
61| Wrap nullable | `O.fromNullable(value)` |
62| Default value | `O.getOrElse(() => default)` |
63| Transform if exists | `O.map(fn)` |
64| Chain optionals | `O.flatMap(fn)` |
65| Wrap try/catch | `E.tryCatch(() => risky(), toError)` |
66| Wrap async | `TE.tryCatch(() => fetch(url), toError)` |
67| Run pipe | `pipe(value, fn1, fn2, fn3)` |
68
69## Pattern Match
70
71```typescript
72// Option
73pipe(maybe, O.match(
74 () => 'nothing',
75 (val) => `got ${val}`
76))
77
78// Either
79pipe(result, E.match(
80 (err) => `error: ${err}`,
81 (val) => `success: ${val}`
82))
83```
84
85## Limitations
86- Use this skill only when the task clearly matches the scope described above.
87- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
88- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.