| name | fp-taskeither-ref |
| description | ALWAYS use this when the user mentions FP Taskeither REF, asks to build, debug, review, document, automate, test, configure, migrate, or make decisions in this domain, or the task clearly depends on FP Taskeither REF; scope: Quick reference for TaskEither. Apply the bundled workflow, references, scripts, Senior Master standard, and Codex strict review gate before final output. |
TaskEither Quick Reference
Selective Reading Rule
Start with:
references/senior-master-standard.md
references/usage-routing.md
references/quality-checklist.md
Then load only the inherited docs, scripts, assets, or examples that match the user's actual task.
TaskEither = async operation that can fail. Like Promise<Either<E, A>>.
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
TaskEither operators and patterns.
Create
import * as TE from 'fp-ts/TaskEither'
TE.right(value)
TE.left(error)
TE.tryCatch(asyncFn, toError)
TE.fromEither(either)
Transform
TE.map(fn)
TE.mapLeft(fn)
TE.flatMap(fn)
TE.orElse(fn)
Execute
const result = await myTaskEither()
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'
const fetchUser = (id: string) => TE.tryCatch(
() => fetch(`/api/users/${id}`).then(r => r.json()),
(e) => ({ type: 'NETWORK_ERROR', message: String(e) })
)
pipe(
fetchUser('123'),
TE.flatMap(user => fetchPosts(user.id)),
TE.map(posts => posts.length)
)
import { sequenceT } from 'fp-ts/Apply'
sequenceT(TE.ApplyPar)(
fetchUser('1'),
(),
()
)
(
(),
.( .(defaultUser)),
.( defaultUser)
)
vs async/await
async function getUser(id: string) {
try {
const res = await fetch(`/api/users/${id}`)
return await res.json()
} catch (e) {
return null
}
}
const getUser = (id: string) => pipe(
TE.tryCatch(() => fetch(`/api/users/${id}`), toNetworkError),
TE.flatMap(res => TE.tryCatch(() => 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.