Suppose I am using the Rng library for simple Monte Carlo simulation (as in that post).
val d : Rng[Double] = double
val point : Rng[(Double, Double)] = pair(d, d)
val points = point.stream(1000)
val tests = points.map(point => if (insideCircle(point)) 1.0 else 0.0)
Now I need to sum all items of tests
tests[0] |+| tests[1] |+| tests[2] ... // Rng[Double] is a monoid
I can do it with fold but I would like to use some "shortcut" (smth. like sum: Seq[M[A]] => M[A], where M is a monoid), instead. Do scala or scalaz have such a function ?
Scalaz has various ops e.g.
suml, assuming there's aFoldabletypeclass instance forStream.