scalaz/scalaz — pull request #869 by markfarrell (2014-12-25 21:36:32+00:00)
Title: Fixed foldLeftM stack overflows on Set #866

Open up scalaz/std/Set.scala. Change the definition of foldRight in SetInstances to:

```scala
def foldRight[A, B](fa: Set[A], z: => B)(f: (A, => B) => B) = {
import scala.collection.mutable.ArrayStack
val s = new ArrayStack[A]
fa.foreach(a => s += a)
var r = z
while (!s.isEmpty) {
val w = r // <-- add this
r = f(s.pop, w)
}
r
}
```

```scala
scala> Set(0).foldLeftM[Option, Int](0) { case (x, y) => Some(x+y) }
res0: Option[Int] = Some(0)

Signed-off-by: Mark