duplicate code is not that bad. reduce duplication over time as you find the common patterns/abstractions, instead of trying to build abstractions too early
The prophet Perlis declared: "It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures."
Efforts to reduce duplication should be focused on chunking out reusable pure functions. Trying to dedupe the flow of logic is almost always a fool's errand.