- Home
- Skills
- Whatiskadudoing
- Fp Ts Skills
- Fp Task Either
fp-task-either_skill
2
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill whatiskadudoing/fp-ts-skills --skill fp-task-either- SKILL.md21.1 KB
Overview
This skill teaches practical async patterns using fp-ts TaskEither to get type-safe error handling in TypeScript. It focuses on lifting promises, composing async flows, and recovering from failures without try/catch. You get patterns for sequencing, parallelism, retries, and integrating validation.
How this skill works
TaskEither<E, A> is a lazy function that returns Promise<Either<E, A>> when executed. The skill shows how to lift promises with tryCatch, convert Option/Either into TaskEither, and compose operations with chain/flatMap, Do notation, and applicative helpers. It also covers mapping/filtering errors, parallel vs sequential execution, controlled concurrency, and fold/match to handle results.
When to use it
- When you want composable, lazy async operations with an explicit error channel.
- When you need to transform or map errors without throwing exceptions.
- When combining multiple dependent or independent API calls in a safe pipeline.
- When you need predictable parallelism (fail-fast vs collect-all) and batching.
- When you want retries, conditional fallbacks, or typed fallbacks in async flows.
Best practices
- Lift external promises with TE.tryCatch and convert runtime errors to a typed error shape.
- Prefer TE.Do and bind for complex workflows to keep intermediate state explicit and typed.
- Choose ApplyPar for parallel, ApplySeq for sequential, and batch large sets to control concurrency.
- Use TE.orElse or TE.alt for controlled fallbacks; use orElseW when error types differ.
- Validate external data with codecs (io-ts) and chainEitherK to turn validation into TaskEither failures.
Example use cases
- Typed API client that returns TaskEither<ApiError, T> for every request, with centralized error mapping.
- Fetch user → team → org as a single pipeline that aborts on first failure or recovers with a fallback.
- Parallel fetching of multiple resources with sequenceArray or traverseArray and optional batching.
- Retrying flaky network calls with exponential backoff implemented via TE.orElse and fp-ts Task helpers.
- Processing orders: build context with TE.Do, validate intermediate data, then perform final creation step.
FAQ
Call the TaskEither function: await myTaskEither(). It returns an Either; use E.isLeft/E.isRight or fold/match to handle outcomes.
When should I use TaskThese or validation instead?
Use TaskThese or applicative validation when you must collect multiple errors from parallel operations instead of failing fast.