Lens based API for statistics calculation (mean, stddev, etc)
This is one way to resolve #146. All examples here will use mean but readily generalizes to all fold based estimators and with some problems to quantiles and like which will require building intermediate vector.
Current implementation of mean have following signature: mean :: (G.Vector v Double) => v Double -> Double and as such could only work with vectors. Which is very inconvenient. Proposal is to take Getting for data structure as parameter
meanOf :: Getting (Endo (Endo MeanKBN)) s Double -> s -> Double
This surprisingly powerful API. Here are examples
meanOf eachwill compute mean of instance ofEachtype class that it will work for vector, lists, Maps and lot of other data structuresmeanof foldedwill work for any FoldablemeanOf (each . each)will compute mean of nested containersmeanOf (each . filtered (>0) . to log)will compute mean of logarithm of every positive number.
So this is very powerful and generic API. Preliminary benchmarks indicate that it's possible to get performance identical to current implementation. Only downside it requires use of lens but I think gained power worth it.