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 Elhanafim(0) 0 installs
Free
Sign in to install

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

See reviews

About

Imported from Elhanafim/WallStreet-Morocco (skills/plugins/antigravity-awesome-skills-claude/skills/fp-taskeither-ref/SKILL.md). Install upstream with npx skills add Elhanafim/WallStreet-Morocco --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.

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/elhanafim-wallstreet-morocco-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.

elhanafim-wallstreet-morocco-fp-taskeither-ref.ocm.jsonjson
{
  "ocm": "1",
  "id": "elhanafim-wallstreet-morocco-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": "Elhanafim",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "fp-ts",
      "taskeither",
      "async",
      "promise",
      "error-handling",
      "quick-reference",
      "github"
    ],
    "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": "github",
      "repository": "https://github.com/Elhanafim/WallStreet-Morocco",
      "path": "skills/plugins/antigravity-awesome-skills-claude/skills/fp-taskeither-ref/SKILL.md",
      "ref": "d5b39a2a68a1f5885a684a0bfe6aed263935e243",
      "url": "https://github.com/Elhanafim/WallStreet-Morocco/blob/d5b39a2a68a1f5885a684a0bfe6aed263935e243/skills/plugins/antigravity-awesome-skills-claude/skills/fp-taskeither-ref/SKILL.md",
      "key": "Elhanafim/WallStreet-Morocco/skills/plugins/antigravity-awesome-skills-claude/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\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)    // ",
  "cost": {
    "context_tokens": 583
  }
}

Fetch it by URL: GET /api/v1/registry/elhanafim-wallstreet-morocco-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.