Mic*_*ael 2 random scala fold scalaz monoids
假设我使用Rng库进行简单的蒙特卡罗模拟(如该帖子中所述).
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)
Run Code Online (Sandbox Code Playgroud)
现在我需要总结所有项目tests
tests[0] |+| tests[1] |+| tests[2] ... // Rng[Double] is a monoid
Run Code Online (Sandbox Code Playgroud)
我可以这样做,fold但我想使用一些"快捷方式"(smth.像sum: Seq[M[A]] => M[A],其中M是一个幺半群),而不是.做scala或scalaz有这样的功能?