Przejdź do treści
Biblioteka skilli
Programowanie · Nauka i wyjaśnianie

fp-either-ref

/fp-either-ref

Podaje skrócone odniesienie do typu Either w fp-ts, przy obsłudze błędów, walidacji i operacji mogących zakończyć się typowanym błędem.

Licencja
MIT
Ostatnia zmiana repozytorium
26.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 26.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Podaje skrócone odniesienie do typu Either w fp-ts, przy obsłudze błędów, walidacji i operacji mogących zakończyć się typowanym błędem.

Oryginalny opis (EN)

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

Jak działa

  1. When to Use
  2. Create
  3. Transform
  4. Extract
  5. Common Patterns
  6. vs try/catch
  7. Limitations
  8. Reference scope
Sekcje z nagłówków SKILL.md, w oryginale · 94 linii, 388 słów
Podgląd SKILL.md
---
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.
risk: none
source: community
date_added: "2026-03-06"
version: 1.0.0
tags: [fp-ts, either, error-handling, validation, quick-reference]
---

# 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

```typescript
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

```typescript
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

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

## Common Patterns

```typescript
import { pipe, identity } from 'fp-ts/function'
import * as E from 'fp-ts/Either'

// Toy validation; an @ check is not complete email 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

```typescript
// ❌ 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.flatMap(data => E.tryCatch(() => process(data), String)),
  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.

## 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.

Official API: [fp-ts modules](https://gcanti.github.io/fp-ts/modules/).

Wersje

RepozytoriumWynikLicencja
Ta strona · FrancoStino/opencode-skills-collection100MIT
LiHongwei-cn/lihongwei-cn100MIT

Identyczna treść występuje jeszcze w 3 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki 2159cb0c5f80 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100fp-taskeither-ref
    Podaje skrócone odniesienie do TaskEither w fp-ts, przy asynchronicznej obsłudze błędów, wywołaniach API i operacjach opartych na Promise, które mogą się nie udać.
  • 100fp-taskeither-ref
    Podaje skrócone odniesienie do TaskEither w fp-ts, przy asynchronicznej obsłudze błędów, wywołaniach API i operacjach opartych na Promise, które mogą się nie udać.
  • 100fp-option-ref
    Podaje skrócone odniesienie do typu Option w fp-ts, przy obsłudze wartości nullable i opcjonalnych danych oraz unikaniu sprawdzania null.
  • 100fp-option-ref
    Podaje skrócone odniesienie do typu Option w fp-ts, przy obsłudze wartości nullable i opcjonalnych danych oraz unikaniu sprawdzania null.
  • 96error-handling
    Opisuje ujednolicony system obsługi błędów: dodawanie endpointów API, zmiany w obsłudze błędów, wywołania API we frontendzie i testy dotyczące błędów.
  • 100moai-ref-api-patterns
    Zawiera referencję wzorców projektowania API REST i GraphQL, konwencji obsługi błędów i walidacji danych wejściowych dla backendu, przy projektowaniu endpointów i przeglądzie kodu serwerowego.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.