[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-65feb363-dc1c-4ef1-be71-0f167b3dd356":3,"$fB0Z39XHyMPqO461NBLLb1Q5Wa6XoUsVaOw-RwYtIcaA":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"65feb363-dc1c-4ef1-be71-0f167b3dd356","fp-either-ref","快速参考：Either 类型。当用户需要错误处理、验证或可能失败并带有类型错误的操作时使用。","cat_life_career","mod_other","sickn33,other","---\nname: fp-either-ref\ndescription: Quick reference for Either type. Use when user needs error handling, validation, or operations that can fail with typed errors.\nrisk: unknown\nsource: community\nversion: 1.0.0\ntags: [fp-ts, either, error-handling, validation, quick-reference]\n---\n\n# 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\u002FEither'\n\nE.right(value)           \u002F\u002F Success\nE.left(error)            \u002F\u002F Failure\nE.fromNullable(err)(x)   \u002F\u002F null → Left(err), else Right(x)\nE.tryCatch(fn, toError)  \u002F\u002F try\u002Fcatch → Either\n```\n\n## Transform\n\n```typescript\nE.map(fn)                \u002F\u002F Transform Right value\nE.mapLeft(fn)            \u002F\u002F Transform Left error\nE.flatMap(fn)            \u002F\u002F Chain (fn returns Either)\nE.filterOrElse(pred, toErr) \u002F\u002F Right → Left if pred fails\n```\n\n## Extract\n\n```typescript\nE.getOrElse(err => default)  \u002F\u002F Get Right or default\nE.match(onLeft, onRight)     \u002F\u002F Pattern match\nE.toUnion(either)            \u002F\u002F E | A (loses type info)\n```\n\n## Common Patterns\n\n```typescript\nimport { pipe } from 'fp-ts\u002Ffunction'\nimport * as E from 'fp-ts\u002FEither'\n\n\u002F\u002F Validation\nconst validateEmail = (s: string): E.Either\u003Cstring, string> =>\n  s.includes('@') ? E.right(s) : E.left('Invalid email')\n\n\u002F\u002F Chain validations (stops at first error)\npipe(\n  E.right({ email: 'test@example.com', age: 25 }),\n  E.flatMap(d => pipe(validateEmail(d.email), E.map(() => d))),\n  E.flatMap(d => d.age >= 18 ? E.right(d) : E.left('Must be 18+'))\n)\n\n\u002F\u002F Convert throwing code\nconst parseJson = (s: string) => E.tryCatch(\n  () => JSON.parse(s),\n  (e) => `Parse error: ${e}`\n)\n```\n\n## vs try\u002Fcatch\n\n```typescript\n\u002F\u002F ❌ try\u002Fcatch - errors not in types\ntry {\n  const data = JSON.parse(input)\n  process(data)\n} catch (e) {\n  handleError(e)\n}\n\n\u002F\u002F ✅ Either - errors explicit in types\npipe(\n  E.tryCatch(() => JSON.parse(input), String),\n  E.map(process),\n  E.match(handleError, identity)\n)\n```\n\nUse Either when **error type matters** and you want to chain operations.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,63,504,"2026-05-16 13:18:35",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"其他","other","mdi-page-next-outline","其他类型Skill",5,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"职场发展","career","mdi-briefcase-outline","面试准备、简历优化、职业规划",4,575,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"18ae7f80-3dd6-48a1-97f2-ddc7d64c7b78","1.0.0","fp-either-ref.zip",1350,"uploads\u002Fskills\u002F65feb363-dc1c-4ef1-be71-0f167b3dd356\u002Ffp-either-ref.zip","c866ab9917e1992312ac0bc966ab3283455f46701795798785ce6722a77a7d33","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":2607}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]