fp-taskeither-ref
Lets your agent give quick references on TaskEither. It's useful for handling errors in asynchronous operations.
What it does
TaskEither is a way to handle asynchronous operations (that take time) which might fail. It ensures errors are managed clearly and in an organized manner.
When to use it
- ✓When making calls to external APIs that might fail.
- ✓When working with Promises that need explicit error handling.
- ✓When building sequences of asynchronous operations where each step can produce an error.
Example of what to ask your AI
“How can I use TaskEither to fetch user data and ensure network or format errors are handled?”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
It works like a promise that, instead of just succeeding or failing, returns a result that can be either a success (with data) or a specific error. You can chain operations, transforming successes or recovering from errors.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add sickn33/agentic-awesome-skills --skill fp-taskeither-refOr download just the file:
curl -L https://raw.githubusercontent.com/sickn33/agentic-awesome-skills/main/plugins/agentic-awesome-skills-claude/skills/fp-taskeither-ref/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
TaskEither Quick Reference
TaskEither = async operation that can fail. Its shape is () => Promise<Either<E, A>>: construction is lazy.
When to Use
- You need a quick fp-ts reference for async operations that can fail.
- The task involves API calls, Promise wrapping, or composing asynchronous error-handling pipelines.
- You want a concise cheat sheet for
TaskEitheroperators and patterns.
Create
import * as TE from 'fp-ts/TaskEither'
import * as T from 'fp-ts/Task'
TE.right(value) // Async success
TE.left(error) // Async failure
TE.tryCatch(asyncFn, toError) // Promise → TaskEither
TE.fromEither(either) // Either → TaskEither
Transform
TE.map(fn) // Transform success value
TE.mapLeft(fn) // Transform error
TE.flatMap(fn) // Chain (fn returns TaskEither)
TE.orElse(fn) // Recover from error
Execute
// TaskEither is lazy - must call () to run
const result = await myTaskEither() // Either<E, A>
// Or pattern match
await pipe(
myTaskEither,
TE.match(
(err) => console.error(err),
(val) => console.log(val)
)
)()
Common Patterns
import { pipe } from 'fp-ts/function'
import * as TE from 'fp-ts/TaskEither'
import * as T from 'fp-ts/Task'
// Wrap fetch
const fetchUser = (id: string, signal: AbortSignal) => TE.tryCatch(
async () => {
const response = await fetch(`/api/users/${encodeURIComponent(id)}`, { signal })
if (!response.ok) throw new Error(`HTTP ${response.status}`)
const body: unknown = await response.json()
return validateUser(body) // Application schema validator; throws on invalid data
},
(e) => ({ type: 'NETWORK_ERROR', message: String(e) })
)
// Chain async calls
pipe(
fetchUser('123', signal),
TE.flatMap(user => fetchPosts(user.id)),
TE.map(posts => posts.length)
)
// Parallel calls
import { sequenceT } from 'fp-ts/Apply'
sequenceT(TE.ApplyPar)(
fetchUser('1', signal),
fetchPosts('1'),
fetchComments('1')
)
// With recovery
pipe(
fetchUser('123', signal),
TE.orElse(() => TE.right(defaultUser)),
TE.getOrElse(() => T.of(defaultUser))
)
vs async/await
// ❌ async/await - errors hidden
async function getUser(id: string) {
try {
const res = await fetch(`/api/users/${id}`)
return await res.json()
} catch (e) {
return null // Error info lost
}
}
// ✅ TaskEither - errors typed and composable
const getUser = (id: string, signal: AbortSignal) => pipe(
TE.tryCatch(() => fetch(`/api/users/${encodeURIComponent(id)}`, { signal }), toNetworkError),
TE.flatMap(res => TE.tryCatch(async () => {
if (!res.ok) throw new Error(`HTTP ${res.status}`)
return validateUser(await res.json())
}, toParseError))
)
Use TaskEither when you need typed errors for async operations.
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.
Reference scope
These are fp-ts 2.x fragments. Supply application variables, types, validators and imports, and check the installed version. map does not catch thrown exceptions. Task has no typed error channel; an improperly wrapped promise can still reject. Use tryCatch at fallible boundaries.
Supply a caller-owned timeout/abort signal and validate response schemas. Parallel application calls need bounded concurrency and authorization for their data, costs and effects; ApplyPar does not cancel work automatically on failure. Error callbacks must redact secrets and private payloads.
Official API: fp-ts modules.
FAQ
What does 'lazy construction' mean?
It means the operation is only executed when you explicitly call it, not when it's defined.
What's the difference between `map` and `flatMap`?
`map` transforms the success value, but the result is still a TaskEither. `flatMap` chains operations, where the function passed also returns a TaskEither, allowing for more complex sequences.
How do I execute the operation?
You need to call the defined function (it returns a Promise) and use `await` to get the result, which will be an `Either` (success or error).
Details
Original description by the author
Quick reference for TaskEither. Use when user needs async error handling, API calls, or Promise-based operations that can fail.
Popularity
- GitHub stars
- 48k
- Ranking position
- #3034
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
00-andruia-consultant
Helps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
sickn33/agentic-awesome-skills
007
Lets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
sickn33/agentic-awesome-skills
10-andruia-skill-smith
Helps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
sickn33/agentic-awesome-skills
20-andruia-niche-intelligence
Lets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
sickn33/agentic-awesome-skills
Similar skills
benchmark-optimization-loop
Has your agent improve something's speed in a measured way. It tests multiple versions and chooses the fastest one that still works correctly.
affaan-m/ECC
change-impact
Helps your agent analyze the impact of code changes before making them. It compares the planned vs. actual results afterward, covering paths, data, tests, and documentation. Useful for risky or system-wide changes.
affaan-m/ECC
click-path-audit
Lets your agent trace all user buttons and interactions to find bugs. It finds issues where functions seem to work alone but fail together. Useful when bugs persist even after debugging.
affaan-m/ECC