Skip to content
Skillv1.0.0

fp-taskeither-ref

Quick reference for TaskEither. Use when user needs async error handling, API calls, or Promise-based operations that can fail.

by sickn33(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from sickn33/agentic-awesome-skills (skills/fp-taskeither-ref/SKILL.md). Install upstream with npx skills add sickn33/agentic-awesome-skills --skill fp-taskeither-ref. Copyright stays with the author.

TaskEither Quick Reference

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)          // 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'

// Wrap fetch
const fetchUser = (id: string) => TE.tryCatch(
  () => fetch(`/api/users/${id}`).then(r => r.json()),
  (e) => ({ type: 'NETWORK_ERROR', message: String(e) })
)

// Chain async calls
pipe(
  fetchUser('123'),
  TE.flatMap(user => fetchPosts(user.id)),
  TE.map(posts => posts.length)
)

// Parallel calls
import { sequenceT } from 'fp-ts/Apply'
sequenceT(TE.ApplyPar)(
  fetchUser('1'),
  fetchPosts('1'),
  fetchComments('1')
)

// With recovery
pipe(
  fetchUser('123'),
  TE.orElse(() => TE.right(defaultUser)),
  TE.getOrElse(() => 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) => 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.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/sickn33-agentic-awesome-skills-fp-taskeither-ref/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

sickn33-agentic-awesome-skills-fp-taskeither-ref.ocm.jsonjson
{
  "ocm": "1",
  "id": "sickn33-agentic-awesome-skills-fp-taskeither-ref",
  "kind": "skill",
  "name": "fp-taskeither-ref",
  "description": "Quick reference for TaskEither. Use when user needs async error handling, API calls, or Promise-based operations that can fail.",
  "publisher": "sickn33",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "fp-ts",
      "taskeither",
      "async",
      "promise",
      "error-handling",
      "quick-reference",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Quick reference for TaskEither. Use when user needs async error handling, API calls, or Promise-based operations that can fail."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/sickn33/agentic-awesome-skills",
      "path": "skills/fp-taskeither-ref/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/sickn33/agentic-awesome-skills/blob/HEAD/skills/fp-taskeither-ref/SKILL.md",
      "key": "sickn33/agentic-awesome-skills/skills/fp-taskeither-ref/SKILL.md"
    }
  },
  "instructions": "# TaskEither Quick Reference\n\nTaskEither = async operation that can fail. Like `Promise<Either<E, A>>`.\n\n## When to Use\n- You need a quick fp-ts reference for async operations that can fail.\n- The task involves API calls, Promise wrapping, or composing asynchronous error-handling pipelines.\n- You want a concise cheat sheet for `TaskEither` operators and patterns.\n\n## Create\n\n```typescript\nimport * as TE from 'fp-ts/TaskEither'\n\nTE.right(value)          // Async success\nTE.left(error)           // Async failure\nTE.tryCatch(asyncFn, toError)  // Promise → TaskEither\nTE.fromEither(either)    // E",
  "cost": {
    "context_tokens": 663
  }
}

Fetch it by URL: GET /api/v1/registry/sickn33-agentic-awesome-skills-fp-taskeither-ref/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.