which is not great (duplication of data, possible inconsistent data, …), as r.Average = f.Float / r.Count.
However, having the value available as r.Average would have the advantage to simplify the code displaying these values in a chart: all code would be displayable with the exact same code.
Maybe consider having ExpensesSummary type without duplication for backend and separate ViewModel type for displaying to user? Or you may add property to it, like this:
type ExpensesSummary =
{ Count: int
Total: float
Media: float }
with
member m.AVerage = m.Total / (float m.Count)
Thanks @evgeny! I’m working in a Jupyter notebook, so I’m not planning on having 2 types, but your suggestion of adding a property seems exactly what I needed!
Note that properties are (IIRC) not stored / cached - so every time you hit that property it’ll recalculate it. Not necessarily a problem for simple properties but worth bearing in mind.