Guide fp-ts Type Choices and Patterns
A decision-guide cheat sheet for choosing between fp-ts's Option, Either, Task, and TaskEither types.
Why it matters
Get expert guidance on selecting the correct fp-ts types like Option, Either, Task, and TaskEither for your TypeScript projects. This asset provides a quick reference for common imports and one-line patterns to streamline your functional programming workflow.
Outcomes
What it gets done
Choose between fp-ts Option, Either, Task, and TaskEither.
Understand common fp-ts imports and their uses.
Apply one-line patterns for common fp-ts operations.
Learn pattern matching for Option and Either types.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-fp-types-ref | bash Overview
fp-ts Quick Reference
A decision-guide cheat sheet for choosing between fp-ts's Option, Either, Task, and TaskEither types, with common imports and one-line usage patterns. Use it when choosing between fp-ts types or needing quick guidance on imports and common patterns for a TypeScript flow.
What it does
A compact decision guide for choosing the right fp-ts type: a flowchart asking whether the operation is async, whether it involves errors, and whether the value might be missing, routing to Either<Error, Value> for sync-with-errors, Option<Value> for sync-nullable, TaskEither<Error, Value> for async-with-errors, TaskOption<Value> for async-nullable, or plain Task<Value> for async-no-failure. It lists the common imports for each type (Option, Either, TaskEither, Task, plus pipe/flow from fp-ts/function and Array utilities) and a one-line-pattern table (wrap nullable, default value, transform if exists, chain optionals, wrap try/catch, wrap async, run a pipe), plus pattern-matching examples for both Option and Either.
import { pipe, flow } from 'fp-ts/function'
When to use - and when NOT to
Use it when choosing between Option, Either, Task, TaskEither, or related fp-ts types, or needing quick guidance on imports and common patterns for a TypeScript flow, rather than a full fp-ts tutorial.
Inputs and outputs
Input: a TypeScript value or operation needing the right fp-ts wrapper type. Output: the recommended type - Option, Either, Task, or TaskEither - its import statement, and a matching one-line pattern.
Integrations
Companion reference to the more detailed fp-either-ref and fp-option-ref cheat sheets for deeper usage of each individual type.
Who it's for
TypeScript developers using fp-ts who need fast guidance on which type fits a given situation rather than re-deriving the decision each time.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.