Updating a function in a type, where the function is a parameter

Can you elaborate on this answer? I do not understand what you mean?

So the expensive things might be

a) evaluating f itself
b) things happening in the loop outside of get_cost.

With get_costI currently have a neat encapsulation of calling the cost function which I would like to keep as an abstraction level, if I would also unpack that – that would be a lot of code to write (also same reason I would prefer just an update function and not new constructions for even MyStruct subtype that I have).