10
Combine Functions into Transform
Goal
Multiple derived values from the same source come from one transform that produces an enriched record.
Before the refactoring
function base(reading) { /* ... */ }
function taxable(reading) { /* ... */ }After the refactoringfunction enrich(reading) {
return { ...reading, base: base(reading), taxable: taxable(reading) };
}Savings
Derivations stay consistent (no two callers compute slightly different versions); cache invalidation becomes obvious.
Note
Building a transform up-front when only one derivation exists is BDUF — wait for the second derivation before introducing the transform.