fp-taskeither-ref_skill

This skill provides quick TaskEither patterns for async error handling, API calls, and Promise-based workflows using fp-ts.

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-taskeither-ref

  • SKILL.md2.3 KB

Overview

This skill is a compact quick reference for using TaskEither from fp-ts to handle async operations that can fail. It highlights creation, transformation, execution patterns, and common use cases like API calls, parallel requests, and typed error recovery. Designed for practical, copy-paste-ready patterns without jargon.

How this skill works

TaskEither represents a lazy async computation that yields either an error (Left) or a value (Right), effectively Promise<Either<E, A>>. The skill shows how to construct TaskEither values (right, left, tryCatch), transform them (map, mapLeft, flatMap, orElse), and execute them by calling the TaskEither or using pattern matching helpers. It also demonstrates sequencing in parallel and recovering from failures while keeping errors typed and composable.

When to use it

  • Performing HTTP or database calls where failures must be tracked explicitly
  • Composing multiple async steps while preserving typed error information
  • Recovering from failures with fallback values or alternative tasks
  • Running several independent async tasks in parallel and combining results
  • Avoiding lost error context that often happens with try/catch and null returns

Best practices

  • Use TE.tryCatch to wrap Promises and provide a deterministic error type
  • Prefer TE.flatMap for sequencing tasks that return TaskEither, TE.map for pure transforms
  • Keep error shapes consistent across your domain to simplify handling and mapping
  • Use TE.orElse to handle recoverable errors and TE.getOrElse at the edge to convert to a plain value
  • Leverage ApplyPar or sequenceT(TE.ApplyPar) for parallel independent requests

Example use cases

  • Wrap fetch calls and parse JSON with separate network and parse error types
  • Chain user fetch → posts fetch → transform posts count with TE.flatMap and TE.map
  • Perform user, posts, and comments requests in parallel and combine the results
  • Provide a default object on API failure using TE.orElse(() => TE.right(defaultValue))
  • Convert an existing Either into a TaskEither when mixing sync validation and async IO

FAQ

TaskEither keeps errors explicit and typed, making composition and recovery predictable, whereas async/await can silently swallow or lose structured error information.

How do I run a TaskEither?

TaskEither is lazy: call the value as a function and await it, e.g. const result = await myTaskEither(); or use TE.match and invoke the returned task.

Can I run tasks in parallel?

Yes—use TE.ApplyPar or utilities like sequenceT(TE.ApplyPar) to execute independent TaskEither instances in parallel.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational