fp-taskeither-ref – Coding skill for AI agents
Quick reference for TaskEither. Use when user needs async error handling, API calls, or Promise-based operations that can fail.
Install the fp-taskeither-ref skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-taskeither-ref-1b8d3.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /fp-taskeither-ref – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-taskeither-ref-1b8d3.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $fp-taskeither-ref – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-taskeither-ref-1b8d3.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /fp-taskeither-ref – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/fp-taskeither-ref-1b8d3.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /fp-taskeither-ref – then describe the task you want done.
SKILL.md content
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 → TaskEitherTransform
TE.map(fn) // Transform success value
TE.mapLeft(fn) // Transform error
TE.flatMap(fn) // Chain (fn returns TaskEither)
TE.orElse(fn) // Recover from errorExecute
// 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](https://gcanti.github.io/fp-ts/modules/).
Related skills
- fp-ts-errors – Handle errors as values using fp-ts Either and TaskEither for cleaner, more predictable…
- fp-ts-pragmatic – A practical, jargon-free guide to fp-ts functional programming - the 80/20 approach that…
- fp-ts-react – Practical patterns for using fp-ts with React - hooks, state, forms, data fetching. Use…
- framework-migration-code-migrate – You are a code migration expert specializing in transitioning codebases between…
- framework-migration-deps-upgrade – You are a dependency management expert specializing in safe, incremental upgrades of…
- self-eval – Honestly evaluate AI work quality using a two-axis scoring system. Use after completing…
- frontend-architecture – A portable, framework-agnostic architecture style for any React or React Native…
- frontend-developer – Build React components, implement responsive layouts, and handle client-side state…