I generally follow the rule. Duplicate code until you have at least three examples. Then you can generalise.
So many times if you dedupe code which appears in two places that at first looks like the same code you later realise it is different behaviour and make the "general" function much more complex.
https://mastodon.gamedev.place/@nickappleton/112319859733386927