| name | fp-either-ref |
| description | Quick reference for Either type. Use when user needs error handling, validation, or operations that can fail with typed errors. |
| type | skill |
| created | 2026-02-27T00:00:00.000Z |
| domain | communication-content |
| category | documentation |
| risk | unknown |
| source | community |
| tags | ["skill","communication-content","documentation","either","ref"] |
Either Quick Reference
Either = success or failure. Right(value) or Left(error).
When to Use
- You need a quick fp-ts reference for typed synchronous error handling.
- The task involves validation, fallible operations, or converting throwing code to
Either.
- You want a compact cheat sheet rather than a long tutorial.
Create
import * as E from 'fp-ts/Either'
E.right(value)
E.left(error)
E.fromNullable(err)(x)
E.tryCatch(fn, toError)
Transform
E.map(fn)
E.mapLeft(fn)
E.flatMap(fn)
E.filterOrElse(pred, toErr)
Extract
E.getOrElse(err => default)
E.match(onLeft, onRight)
E.toUnion(either)
Common Patterns
import { pipe } from 'fp-ts/function'
import * E
validateEmail = (: ): E.<, > =>
s.() ? E.(s) : E.()
(
E.({ : , : }),
E.( ((d.), E.( d))),
E.( d. >= ? E.(d) : E.())
)
= () => E.(
.(s),
)