Skip to content
OpenSmartRoute
Skillv1.0.0

fp-either-ref

Quick reference for Either type. Use when user needs error handling, validation, or operations that can fail with typed errors.

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

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

See reviews

About

Imported from HenriqueMC17/agente-core (modules/development/fp-either-ref/SKILL.md). Install upstream with npx skills add HenriqueMC17/agente-core --skill fp-either-ref. Copyright stays with the author.

Either Quick Reference

Either = success or failure. Right(value) or Left(error).

When to Use

  • You need a quick fp-ts reference for typed synchronous error handling.
  • The task involves validation, fallible operations, or converting throwing code to Either.
  • You want a compact cheat sheet rather than a long tutorial.

Create

import * as E from 'fp-ts/Either'

E.right(value)           // Success
E.left(error)            // Failure
E.fromNullable(err)(x)   // null → Left(err), else Right(x)
E.tryCatch(fn, toError)  // try/catch → Either

Transform

E.map(fn)                // Transform Right value
E.mapLeft(fn)            // Transform Left error
E.flatMap(fn)            // Chain (fn returns Either)
E.filterOrElse(pred, toErr) // Right → Left if pred fails

Extract

E.getOrElse(err => default)  // Get Right or default
E.match(onLeft, onRight)     // Pattern match
E.toUnion(either)            // E | A (loses type info)

Common Patterns

import { pipe } from 'fp-ts/function'
import * as E from 'fp-ts/Either'

// Validation
const validateEmail = (s: string): E.Either<string, string> =>
  s.includes('@') ? E.right(s) : E.left('Invalid email')

// Chain validations (stops at first error)
pipe(
  E.right({ email: 'test@example.com', age: 25 }),
  E.flatMap(d => pipe(validateEmail(d.email), E.map(() => d))),
  E.flatMap(d => d.age >= 18 ? E.right(d) : E.left('Must be 18+'))
)

// Convert throwing code
const parseJson = (s: string) => E.tryCatch(
  () => JSON.parse(s),
  (e) => `Parse error: ${e}`
)

vs try/catch

// ❌ try/catch - errors not in types
try {
  const data = JSON.parse(input)
  process(data)
} catch (e) {
  handleError(e)
}

// ✅ Either - errors explicit in types
pipe(
  E.tryCatch(() => JSON.parse(input), String),
  E.map(process),
  E.match(handleError, identity)
)

Use Either when error type matters and you want to chain 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/henriquemc17-agente-core-fp-either-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.

henriquemc17-agente-core-fp-either-ref.ocm.jsonjson
{
  "ocm": "1",
  "id": "henriquemc17-agente-core-fp-either-ref",
  "kind": "skill",
  "name": "fp-either-ref",
  "description": "Quick reference for Either type. Use when user needs error handling, validation, or operations that can fail with typed errors.",
  "publisher": "HenriqueMC17",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "fp-ts",
      "either",
      "error-handling",
      "validation",
      "quick-reference",
      "github"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Quick reference for Either type. Use when user needs error handling, validation, or operations that can fail with typed errors."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "github",
      "repository": "https://github.com/HenriqueMC17/agente-core",
      "path": "modules/development/fp-either-ref/SKILL.md",
      "ref": "0a89333dda845fb647b94921d1ab8868e353c3a7",
      "url": "https://github.com/HenriqueMC17/agente-core/blob/0a89333dda845fb647b94921d1ab8868e353c3a7/modules/development/fp-either-ref/SKILL.md",
      "key": "HenriqueMC17/agente-core/modules/development/fp-either-ref/SKILL.md"
    }
  },
  "instructions": "# Either Quick Reference\n\nEither = success or failure. `Right(value)` or `Left(error)`.\n\n## When to Use\n- You need a quick fp-ts reference for typed synchronous error handling.\n- The task involves validation, fallible operations, or converting throwing code to `Either`.\n- You want a compact cheat sheet rather than a long tutorial.\n\n## Create\n\n```typescript\nimport * as E from 'fp-ts/Either'\n\nE.right(value)           // Success\nE.left(error)            // Failure\nE.fromNullable(err)(x)   // null → Left(err), else Right(x)\nE.tryCatch(fn, toError)  // try/catch → Either\n```\n\n## Transform\n\n```types",
  "cost": {
    "context_tokens": 578
  }
}

Fetch it by URL: GET /api/v1/registry/henriquemc17-agente-core-fp-either-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.