fp-either-ref

Solid

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

AI & Automation 39,350 stars 6386 forks Updated today MIT

Install

View on GitHub

Quality Score: 97/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

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

Details

Author
sickn33
Repository
sickn33/antigravity-awesome-skills
Created
4 months ago
Last Updated
today
Language
Python
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category