FP Pipeline Refactor
Use this skill when code needs to move from imperative style to Effect + kitz functional composition.
Goals
- •Prefer pipeline-friendly composition over statement-by-statement mutation.
- •Use Effect-native data structures:
- •
HashMap/HashSet - •mutable variants only when profiling proves they are needed.
- •
- •Remove untyped boundaries:
- •avoid
JSON.parse - •avoid
try/catch - •avoid
Promiseorchestration - •avoid
anyand type assertions
- •avoid
- •Bridge untyped IO with
Schemadecode/encode at boundaries.
Repeatable Refactor Flow
- •Identify imperative hotspots.
- •Normalize data flow into pure transforms and
Effect.genorchestration. - •Replace native
Map/Setwith EffectHashMap/HashSetwhere the module is already in Effect context. - •Replace
JSON.parsewithSchema.decodeUnknown*and explicit schema models. - •Replace
try/catchwithEffect.try,Effect.tryPromise,Either,Option, and typed error channels. - •Replace promise chains with
Effectcombinators (Effect.all,Effect.forEach,Effect.promise,Effect.async). - •Remove
anyand assertions (as,<T>) by introducing schema/constructor functions at boundaries. - •Run lint/tests and keep behavior stable.
Refactor Prompt Template
md
Refactor this module to Effect-first functional composition. Constraints: - Use pipeline-friendly, curried composition patterns. - Prefer Effect data structures (`HashMap`/`HashSet`; mutable variants only if necessary). - No `JSON.parse` (use Effect Schema decode/encode codecs). - No `try/catch` (use `Effect.try`, `Either`, `Option`, typed errors). - No Promise orchestration (use Effect combinators only). - No `any`, no assertion casts; rely on inference + schema at IO boundaries. Deliverables: 1. Updated implementation. 2. Updated tests proving behavior unchanged. 3. Short notes listing removed anti-patterns and replacement patterns.