본문으로 건너뛰기
Skillpedia
일반 코딩48k · #4641

fp-either-ref

하는 일

이 도구는 프로그램의 오류를 체계적인 방식으로 관리하도록 돕습니다. 무언가 성공했는지(값이 있는지) 실패했는지(특정 오류 메시지가 있는지) 알 수 있고, 프로그램이 예고 없이 충돌하지 않게 합니다.

사용하는 경우

  • ✓사용하기 전에 데이터가 올바른지 확인해야 할 때.
  • ✓파일 읽기처럼 실패할 수 있는 작업을 수행할 때.
  • ✓오류를 던질 수 있는 코드를 프로그램이 이해하는 「성공」 또는 「실패」 형식으로 바꿀 때.

스킬 링크

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-either-ref/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-either-ref/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이메일이 유효한지 확인하고, 유효하지 않으면 명확한 오류 메시지를 보여 주려면 어떻게 하나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

두 가지 경로를 정의해 작동합니다. 하나는 기대한 결과가 담긴 성공 경로이고, 다른 하나는 문제 설명이 담긴 실패 경로입니다. 결과에 따라 어느 경로를 따를지 선택할 수 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

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 => fallbackValue)  // Get Right or default
E.match(onLeft, onRight)     // Pattern match
E.toUnion(either)            // E | A (loses type info)

Common Patterns

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

// ❌ 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.

자주 묻는 질문

「Right」과 「Left」의 차이는 무엇인가요?

「Right」은 성공을 나타내며 기대한 값을 담습니다. 「Left」는 실패를 나타내며 발생한 오류 메시지나 오류 유형을 담습니다.

오류를 던지는 코드(예: 파일 읽기)에서 사용할 수 있나요?

네, 도구에는 오류가 날 수 있는 작업을 「Right」(성공) 또는 「Left」(실패) 결과로 바꾸는 특정 함수(`tryCatch`)가 있습니다.

성공하거나 오류가 날 수 있는 결과를 최종적으로 어떻게 얻나요?

오류가 발생하면 기본값을 제공하는 `getOrElse` 같은 함수를 쓰거나, 성공인지 오류인지에 따라 다른 동작을 하도록 `match`를 사용할 수 있습니다.

상세 정보

작성자의 원본 설명

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

repo: sickn33/agentic-awesome-skills

인기도

GitHub 스타
48k
순위
#4641
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬