Practical Data Transformations
Use functional TypeScript patterns for everyday data reshaping: arrays, objects, normalized API state, grouping, aggregation, and null-safe access. Prefer clear native methods for simple cases and reach for fp-ts where composition, absence, or typed failure matters.
When to Use
Transforming arrays, object shapes, API responses, grouped records, aggregates, or nested optional data.
Replacing verbose loops with map, filter, reduce, flatMap, grouping utilities, or small reusable predicates.
Deciding whether native JavaScript methods, custom helpers, or fp-ts abstractions are the right fit.
When Not to Use
A simple direct loop is clearer and the transformation is not reused or composed.
The transformation is performance-critical and should be benchmarked before introducing extra abstractions.
The task requires fp-ts error modeling rather than data reshaping; use fp-refactor or fp-ts error-handling guidance instead.
Core Workflow
Name the input shape, output shape, and the invariant the transform must preserve.
Choose the smallest clear primitive: map for one-to-one, filter for selection, reduce for accumulation, flatMap for flattening, and grouping helpers for indexes.
Extract predicates, mappers, and reducers into named functions when they are reused or hide business meaning.
Normalize API responses into app state before rendering so UI code stays simple.
Use Option or safe-access helpers when absence is expected and must be composed.
Add table-style tests that cover empty inputs, missing fields, duplicate keys, nullish values, and representative real-world payloads.
Reference Map
Read references/full-guidance.md when the task needs the complete examples and edge cases. It includes:
Array operations: map, filter, reduce, chaining, and fp-ts Array examples.
Object transformations: pick, omit, merge, deep merge, and immutable nested updates.
Data normalization, grouping, aggregation, null-safe access, and real-world examples.
Guidance on when to use native methods, fp-ts, custom utilities, and performance-conscious alternatives.
Safety and Quality Rules
Avoid clever point-free code when named functions would make business intent clearer.
Preserve input immutability unless mutation is intentionally contained and documented.
Handle missing, null, duplicate, and empty cases explicitly before shipping transforms into UI or reporting code.
Progressive Loading
Start with this entrypoint for routing and planning. Load references/full-guidance.md only after the task clearly requires deep implementation detail, code examples, validation checklists, or troubleshooting guidance.
1---2name: fp-data-transforms3description: Use when transforming TypeScript arrays, objects, grouped data, API responses, aggregations, or nested nullable values with practical functional patterns.4license: MIT5---67# Practical Data Transformations89Use functional TypeScript patterns for everyday data reshaping: arrays, objects, normalized API state, grouping, aggregation, and null-safe access. Prefer clear native methods for simple cases and reach for fp-ts where composition, absence, or typed failure matters.1011## When to Use1213- Transforming arrays, object shapes, API responses, grouped records, aggregates, or nested optional data.1415- Replacing verbose loops with map, filter, reduce, flatMap, grouping utilities, or small reusable predicates.1617- Deciding whether native JavaScript methods, custom helpers, or fp-ts abstractions are the right fit.1819## When Not to Use2021- A simple direct loop is clearer and the transformation is not reused or composed.2223- The transformation is performance-critical and should be benchmarked before introducing extra abstractions.2425- The task requires fp-ts error modeling rather than data reshaping; use `fp-refactor` or fp-ts error-handling guidance instead.2627## Core Workflow28291. Name the input shape, output shape, and the invariant the transform must preserve.30312. Choose the smallest clear primitive: map for one-to-one, filter for selection, reduce for accumulation, flatMap for flattening, and grouping helpers for indexes.32333. Extract predicates, mappers, and reducers into named functions when they are reused or hide business meaning.34354. Normalize API responses into app state before rendering so UI code stays simple.36375. Use Option or safe-access helpers when absence is expected and must be composed.38396. Add table-style tests that cover empty inputs, missing fields, duplicate keys, nullish values, and representative real-world payloads.4041## Reference Map4243Read `references/full-guidance.md` when the task needs the complete examples and edge cases. It includes:4445- Array operations: map, filter, reduce, chaining, and fp-ts Array examples.4647- Object transformations: pick, omit, merge, deep merge, and immutable nested updates.4849- Data normalization, grouping, aggregation, null-safe access, and real-world examples.5051- Guidance on when to use native methods, fp-ts, custom utilities, and performance-conscious alternatives.5253## Safety and Quality Rules5455- Avoid clever point-free code when named functions would make business intent clearer.5657- Preserve input immutability unless mutation is intentionally contained and documented.5859- Handle missing, null, duplicate, and empty cases explicitly before shipping transforms into UI or reporting code.6061## Progressive Loading6263Start with this entrypoint for routing and planning. Load `references/full-guidance.md` only after the task clearly requires deep implementation detail, code examples, validation checklists, or troubleshooting guidance.