I have a list of some ~10.000 observations in a custom data type observations :: [Obs]
that I want to aggregate into a statistics object :: Stat
. A fold seemed like a sensible choice. I find myself with two options.
(1) Define a function accumulate :: Stat -> Obs -> Stat
that I then left fold (strictly). foldl' accumulate acc0 observations
But my statistics object only contain accumulators such as Count and Sum, so there should be a monoidal structure. That gives me one more option
(2) define a convert :: Obs -> Stat
and use foldMap from Data.Foldable likefoldMap convert observations
.
my question What reasons are there for going the monoidal way? Performance? Maintainability? Other?