How to remove the function for working with lenses?

I have currently defined two functions:

avg :: (Fractional e) => [e] -> e avg e = uncurry (/) $ foldl' (\(a,l) v -> (a+v,l+1)) (0.0,0.0) e avgOf :: (Fractional a) => Getting (Endo (Endo (a, a))) sa -> s -> a avgOf gs = uncurry (/) $ foldlOf' g accfun (0.0,0.0) s where accfun (a,l) v = (a+v, l+1) 

I get the impression that there should be an easy way to get rid of the whole avgOf implementation and replace it with a simple one that just β€œraises” avg for working with lenses.

+4
source share
1 answer

You can use partsOf to build it from solid fabric.

 avgOf l xs = xs^..partsOf l.to avg 
+3
source

Source: https://habr.com/ru/post/1486689/


All Articles